Skip to content

Commit

Permalink
Merge pull request #31 from sandrask/issue-30
Browse files Browse the repository at this point in the history
fix: Issuer info should be read from profile instead of create request
  • Loading branch information
fqutishat committed Jan 23, 2020
2 parents 6450511 + 4894a2e commit def1f9f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 25 deletions.
2 changes: 1 addition & 1 deletion pkg/restapi/vc/operation/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type ProfileResponse struct {
URI string `json:"uri"`
SignatureType string `json:"signatureType"`
Creator string `json:"creator"`
IssueDate *time.Time `json:"issueDate"`
Created *time.Time `json:"created"`
}

// VerifyCredentialResponse describes verify credential response
Expand Down
9 changes: 6 additions & 3 deletions pkg/restapi/vc/operation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,10 @@ func createCredential(profile *ProfileResponse, data *CreateCredential) (*verifi
credential.Context = []string{credentialContext}
credential.Subject = data.Subject
credential.Types = data.Type
credential.Issuer = data.Issuer
credential.Issuer = verifiable.Issuer{
ID: profile.DID,
Name: profile.Name,
}
credential.Issued = &issueDate
credential.ID = profile.URI + "/" + uuid.New().String()

Expand All @@ -252,11 +255,11 @@ func (c *Operation) createProfile(pr *ProfileRequest) (*ProfileResponse, error)
return nil, err
}

issueDate := time.Now().UTC()
created := time.Now().UTC()
profileResponse := &ProfileResponse{
Name: pr.Name,
URI: pr.URI,
IssueDate: &issueDate,
Created: &created,
DID: pr.DID,
SignatureType: pr.SignatureType,
Creator: pr.Creator,
Expand Down
18 changes: 5 additions & 13 deletions pkg/restapi/vc/operation/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ const testCreateCredentialRequest = `{
"name": "Jayden Doe",
"spouse": "did:example:c276e12ec21ebfeb1f712ebc6f1"
},
"profile": "issuer",
"issuer": {
"id": "did:example:76e12ec712ebc6f1c221ebfeb1f",
"name": "Example University"
}
"profile": "test"
}`

const testInvalidProfileForCreateCredential = `{
Expand All @@ -58,11 +54,7 @@ const testIncorrectCredential = `{
"name": "Jayden Doe",
"spouse": "did:example:c276e12ec21ebfeb1f712ebc6f1"
},
"profile": "test",
"issuer": {
"id": "did:example:76e12ec712ebc6f1c221ebfeb1f",
"name": "Example University"
}
"profile": "test"
}`

const testIssuerProfile = `{
Expand Down Expand Up @@ -124,8 +116,8 @@ func TestCreateCredentialHandler(t *testing.T) {
require.NoError(t, err)

require.Equal(t, http.StatusCreated, rr.Code)
require.Equal(t, "did:example:76e12ec712ebc6f1c221ebfeb1f", vc.Issuer.ID)
require.Equal(t, "Example University", vc.Issuer.Name)
require.Equal(t, getTestProfile().DID, vc.Issuer.ID)
require.Equal(t, getTestProfile().Name, vc.Issuer.Name)
})
t.Run("create credential error by passing invalid request", func(t *testing.T) {
req, err := http.NewRequest(http.MethodPost, createCredentialEndpoint, bytes.NewBuffer([]byte("")))
Expand Down Expand Up @@ -400,7 +392,7 @@ func TestCreate(t *testing.T) {
log.SetOutput(&logContents)

op.createCredentialHandler(b, req)
require.Contains(t, logContents.String(), "Unable to send error response, response writer failed")
require.Contains(t, logContents.String(), "Unable to send error message, response writer failed")
}

func TestOperation_validateProfileRequest(t *testing.T) {
Expand Down
16 changes: 8 additions & 8 deletions pkg/restapi/vc/operation/profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ func TestCredentialRecord_SaveProfile(t *testing.T) {
record := NewProfile(store)
require.NotNil(t, record)

issueDate := time.Now().UTC()
created := time.Now().UTC()
value := &ProfileResponse{
Name: "issuer",
URI: "https://example.com/credentials/1872",
IssueDate: &issueDate,
Name: "issuer",
URI: "https://example.com/credentials/1872",
Created: &created,
}

err := record.SaveProfile(value)
Expand All @@ -45,11 +45,11 @@ func TestCredentialRecord_GetProfile(t *testing.T) {
record := NewProfile(store)
require.NotNil(t, record)

issueDate := time.Now().UTC()
created := time.Now().UTC()
valueStored := &ProfileResponse{
Name: "issuer",
URI: "https://example.com/credentials",
IssueDate: &issueDate,
Name: "issuer",
URI: "https://example.com/credentials",
Created: &created,
}

err := record.SaveProfile(valueStored)
Expand Down

0 comments on commit def1f9f

Please sign in to comment.