Supporess the 'expires' field in public Authorizations
This commit is contained in:
parent
7f8f12c91b
commit
d47b7c12ac
|
|
@ -265,7 +265,11 @@ type Authorization struct {
|
||||||
|
|
||||||
// The date after which this authorization will be no
|
// The date after which this authorization will be no
|
||||||
// longer be considered valid
|
// longer be considered valid
|
||||||
Expires time.Time `json:"expires,omitempty" db:"expires"`
|
Expires time.Time `json:"-" db:"expires"`
|
||||||
|
|
||||||
|
// This field is used only for marshaling, because time.Time
|
||||||
|
// does not have proper omitempty behavior (see below)
|
||||||
|
RawExpires *time.Time `json:"expires,omitempty" db:"-"`
|
||||||
|
|
||||||
// An array of challenges objects used to validate the
|
// An array of challenges objects used to validate the
|
||||||
// applicant's control of the identifier. For authorizations
|
// applicant's control of the identifier. For authorizations
|
||||||
|
|
@ -279,6 +283,17 @@ type Authorization struct {
|
||||||
Combinations [][]int `json:"combinations,omitempty" db:"combinations"`
|
Combinations [][]int `json:"combinations,omitempty" db:"combinations"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This method needs to be called before marshaling an Authorization
|
||||||
|
// object for public consumption, in order suppress the "expires" field.
|
||||||
|
// The Go time.Time type does not have proper behavior with respect to omitempty
|
||||||
|
// https://github.com/golang/go/issues/4357
|
||||||
|
func (authz *Authorization) PrepareForPublicMarshal() {
|
||||||
|
if !authz.Expires.IsZero() {
|
||||||
|
t := authz.Expires
|
||||||
|
authz.RawExpires = &t
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Fields of this type get encoded and decoded JOSE-style, in base64url encoding
|
// Fields of this type get encoded and decoded JOSE-style, in base64url encoding
|
||||||
// with stripped padding.
|
// with stripped padding.
|
||||||
type JsonBuffer []byte
|
type JsonBuffer []byte
|
||||||
|
|
|
||||||
|
|
@ -339,6 +339,7 @@ func (wfe *WebFrontEndImpl) NewAuthorization(response http.ResponseWriter, reque
|
||||||
authzURL := wfe.AuthzBase + string(authz.ID)
|
authzURL := wfe.AuthzBase + string(authz.ID)
|
||||||
authz.ID = ""
|
authz.ID = ""
|
||||||
authz.RegistrationID = 0
|
authz.RegistrationID = 0
|
||||||
|
authz.PrepareForPublicMarshal()
|
||||||
responseBody, err := json.Marshal(authz)
|
responseBody, err := json.Marshal(authz)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
wfe.sendError(response, "Error marshaling authz", err, http.StatusInternalServerError)
|
wfe.sendError(response, "Error marshaling authz", err, http.StatusInternalServerError)
|
||||||
|
|
@ -682,6 +683,7 @@ func (wfe *WebFrontEndImpl) Authorization(response http.ResponseWriter, request
|
||||||
authz.ID = ""
|
authz.ID = ""
|
||||||
authz.RegistrationID = 0
|
authz.RegistrationID = 0
|
||||||
|
|
||||||
|
authz.PrepareForPublicMarshal()
|
||||||
jsonReply, err := json.Marshal(authz)
|
jsonReply, err := json.Marshal(authz)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
wfe.sendError(response, "Failed to marshal authz", err, http.StatusInternalServerError)
|
wfe.sendError(response, "Failed to marshal authz", err, http.StatusInternalServerError)
|
||||||
|
|
|
||||||
|
|
@ -749,7 +749,7 @@ func TestAuthorization(t *testing.T) {
|
||||||
t, responseWriter.Header().Get("Link"),
|
t, responseWriter.Header().Get("Link"),
|
||||||
"</acme/new-cert>;rel=\"next\"")
|
"</acme/new-cert>;rel=\"next\"")
|
||||||
|
|
||||||
test.AssertEquals(t, responseWriter.Body.String(), "{\"identifier\":{\"type\":\"dns\",\"value\":\"test.com\"},\"expires\":\"0001-01-01T00:00:00Z\"}")
|
test.AssertEquals(t, responseWriter.Body.String(), "{\"identifier\":{\"type\":\"dns\",\"value\":\"test.com\"}}")
|
||||||
|
|
||||||
var authz core.Authorization
|
var authz core.Authorization
|
||||||
err := json.Unmarshal([]byte(responseWriter.Body.String()), &authz)
|
err := json.Unmarshal([]byte(responseWriter.Body.String()), &authz)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue