Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
Added e2e test for automatic issuance and bug fixes. (#255)
Browse files Browse the repository at this point in the history
  • Loading branch information
andresuribe87 authored Jan 13, 2023
1 parent ffa73c4 commit 46abf9a
Show file tree
Hide file tree
Showing 12 changed files with 220 additions and 124 deletions.
20 changes: 20 additions & 0 deletions integration/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,3 +426,23 @@ func ReviewApplication(params reviewApplicationParams) (string, error) {

return output, nil
}

type issuanceTemplateParams struct {
SchemaID string
ManifestID string
IssuerID string
}

func CreateIssuanceTemplate(params issuanceTemplateParams) (string, error) {
logrus.Println("\n\nCreating Issuance Template:")
issuanceTemplateJSON, err := resolveTemplate(params, "issuance-template-input.json")
if err != nil {
return "", err
}
output, err := put(endpoint+version+"issuancetemplates", issuanceTemplateJSON)
if err != nil {
return "", errors.Wrapf(err, "creating issuance template yielded output: %s", output)
}

return output, nil
}
95 changes: 95 additions & 0 deletions integration/steelthread_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,101 @@ func TestCreateCredentialManifestIntegration(t *testing.T) {
assert.NotEmpty(t, manifestID)
}

func TestCreateIssuanceTemplateIntegration(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}

issuerDID, err := GetValue(steelThreadContext, "issuerDID")
assert.NoError(t, err)
assert.NotEmpty(t, issuerDID)

schemaID, err := GetValue(steelThreadContext, "schemaID")
assert.NoError(t, err)
assert.NotEmpty(t, schemaID)

cmOutput, err := CreateCredentialManifest(credManifestParams{
IssuerID: issuerDID.(string),
SchemaID: schemaID.(string),
})
assert.NoError(t, err)

manifestID, err := getJSONElement(cmOutput, "$.credential_manifest.id")
SetValue(steelThreadContext, "manifestWithIssuanceTemplateID", manifestID)
assert.NoError(t, err)
assert.NotEmpty(t, manifestID)

presentationDefinitionID, err := getJSONElement(cmOutput, "$.credential_manifest.presentation_definition.id")
SetValue(steelThreadContext, "presentationDefinitionWithIssuanceTemplateID", presentationDefinitionID)
assert.NoError(t, err)
assert.NotEmpty(t, presentationDefinitionID)

itOutput, err := CreateIssuanceTemplate(issuanceTemplateParams{
SchemaID: schemaID.(string),
ManifestID: manifestID,
IssuerID: issuerDID.(string),
})
assert.NoError(t, err)

issuanceTemplateID, err := getJSONElement(itOutput, "$.id")
assert.NoError(t, err)
assert.NotEmpty(t, issuanceTemplateID)
SetValue(steelThreadContext, "issuanceTemplateID", issuanceTemplateID)
}

func TestSubmitApplicationWithIssuanceTemplateIntegration(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}

credentialJWT, err := GetValue(steelThreadContext, "credentialJWT")
assert.NoError(t, err)
assert.NotEmpty(t, credentialJWT)

presentationDefinitionID, err := GetValue(steelThreadContext, "presentationDefinitionWithIssuanceTemplateID")
assert.NoError(t, err)
assert.NotEmpty(t, presentationDefinitionID)

manifestID, err := GetValue(steelThreadContext, "manifestWithIssuanceTemplateID")
assert.NoError(t, err)
assert.NotEmpty(t, manifestID)

aliceDID, err := GetValue(steelThreadContext, "aliceDID")
assert.NoError(t, err)
assert.NotEmpty(t, aliceDID)

aliceDIDPrivateKey, err := GetValue(steelThreadContext, "aliceDIDPrivateKey")
assert.NoError(t, err)
assert.NotEmpty(t, aliceDIDPrivateKey)

credAppJWT, err := CreateCredentialApplicationJWT(credApplicationParams{
DefinitionID: presentationDefinitionID.(string),
ManifestID: manifestID.(string),
}, credentialJWT.(string), aliceDID.(string), aliceDIDPrivateKey.(string))
assert.NoError(t, err)
assert.NotEmpty(t, credAppJWT)

submitApplicationOutput, err := SubmitApplication(applicationParams{
ApplicationJWT: credAppJWT,
})
assert.NoError(t, err)
assert.NotEmpty(t, submitApplicationOutput)

isDone, err := getJSONElement(submitApplicationOutput, "$.done")
assert.NoError(t, err)
assert.Equal(t, "true", isDone)

credentialResponseID, err := getJSONElement(submitApplicationOutput, "$.result.response.credential_response.id")
assert.NoError(t, err)

opCredentialResponse, err := getJSONElement(submitApplicationOutput, "$.result.response")
assert.NoError(t, err)

responsesOutput, err := get(endpoint + version + "manifests/responses/" + credentialResponseID)
assert.NoError(t, err)

assert.JSONEq(t, responsesOutput, opCredentialResponse)
}
func TestSubmitAndReviewApplicationIntegration(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
Expand Down
22 changes: 22 additions & 0 deletions integration/testdata/issuance-template-input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"credentialManifest": "{{.ManifestID}}",
"issuer": "{{.IssuerID}}",
"credentials": [
{
"id": "kyc_credential",
"schema": "{{.SchemaID}}",
"credentialInputDescriptor": "kyc1",
"data": {
"givenName": "$.credentialSubject.givenName",
"familyName": "$.credentialSubject.familyName",
"postalAddress": {
"addressRegion": "CA"
}
},
"expiry": {
"time": "2022-10-31T00:00:00Z"
},
"revocable": true
}
]
}
5 changes: 3 additions & 2 deletions pkg/server/middleware/panics.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ func Panics() framework.Middleware {
defer func() {
if r := recover(); r != nil {
// log the stack trace for this panic'd goroutine
err = errors.Errorf("%s: \n%s", v.TraceID, debug.Stack())
stack := debug.Stack()
err = errors.Errorf("%s: \n%s", v.TraceID, stack)

logrus.Infof("%s: PANIC :\n%s", v.TraceID, debug.Stack())
logrus.Infof("%s: PANIC : %s : \n%s", r, v.TraceID, stack)
}
}()

Expand Down
11 changes: 7 additions & 4 deletions pkg/server/router/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,10 @@ func (mr ManifestRouter) DeleteApplication(ctx context.Context, w http.ResponseW
}

type GetResponseResponse struct {
ID string `json:"id"`
Response manifestsdk.CredentialResponse `json:"response"`
Response manifestsdk.CredentialResponse `json:"credential_response"`
// this is an interface type to union Data Integrity and JWT style VCs
Credentials any `json:"verifiableCredentials,omitempty"`
ResponseJWT keyaccess.JWT `json:"responseJwt,omitempty"`
}

// GetResponse godoc
Expand Down Expand Up @@ -450,8 +452,9 @@ func (mr ManifestRouter) GetResponse(ctx context.Context, w http.ResponseWriter,
}

resp := GetResponseResponse{
ID: gotResponse.Response.ID,
Response: gotResponse.Response,
Response: gotResponse.Response,
Credentials: gotResponse.Credentials,
ResponseJWT: gotResponse.ResponseJWT,
}
return framework.Respond(ctx, w, resp, http.StatusOK)
}
Expand Down
90 changes: 27 additions & 63 deletions pkg/server/server_issuance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,9 @@ func TestIssuanceRouter(t *testing.T) {
{
ID: "output_descriptor_1",
Schema: createdSchema.Schema.ID,
Data: issuing.CredentialTemplateData{
Claims: issuing.ClaimTemplates{
Data: map[string]any{
"foo": "bar",
"hello": "$.vcsomething.something",
},
},
Data: issuing.ClaimTemplates{
"foo": "bar",
"hello": "$.vcsomething.something",
},
Expiry: issuing.TimeLike{
Time: &now,
Expand All @@ -68,13 +64,9 @@ func TestIssuanceRouter(t *testing.T) {
{
ID: "output_descriptor_1",
Schema: "",
Data: issuing.CredentialTemplateData{
Claims: issuing.ClaimTemplates{
Data: map[string]any{
"foo": "bar",
"hello": "$.vcsomething.something",
},
},
Data: issuing.ClaimTemplates{
"foo": "bar",
"hello": "$.vcsomething.something",
},
Expiry: issuing.TimeLike{
Time: &now,
Expand Down Expand Up @@ -118,13 +110,9 @@ func TestIssuanceRouter(t *testing.T) {
{
ID: "",
Schema: createdSchema.Schema.ID,
Data: issuing.CredentialTemplateData{
Claims: issuing.ClaimTemplates{
Data: map[string]any{
"foo": "bar",
"hello": "$.vcsomething.something",
},
},
Data: issuing.ClaimTemplates{
"foo": "bar",
"hello": "$.vcsomething.something",
},
Expiry: issuing.TimeLike{
Time: &now,
Expand All @@ -145,13 +133,9 @@ func TestIssuanceRouter(t *testing.T) {
{
ID: "output_descriptor_1",
Schema: createdSchema.Schema.ID,
Data: issuing.CredentialTemplateData{
Claims: issuing.ClaimTemplates{
Data: map[string]any{
"foo": "bar",
"hello": "$.vcsomething.something",
},
},
Data: issuing.ClaimTemplates{
"foo": "bar",
"hello": "$.vcsomething.something",
},
Expiry: issuing.TimeLike{
Time: &now,
Expand All @@ -173,13 +157,9 @@ func TestIssuanceRouter(t *testing.T) {
{
ID: "output_descriptor_1",
Schema: "fake schema",
Data: issuing.CredentialTemplateData{
Claims: issuing.ClaimTemplates{
Data: map[string]any{
"foo": "bar",
"hello": "$.vcsomething.something",
},
},
Data: issuing.ClaimTemplates{
"foo": "bar",
"hello": "$.vcsomething.something",
},
Expiry: issuing.TimeLike{
Time: &now,
Expand All @@ -200,13 +180,9 @@ func TestIssuanceRouter(t *testing.T) {
{
ID: "output_descriptor_1",
Schema: createdSchema.ID,
Data: issuing.CredentialTemplateData{
Claims: issuing.ClaimTemplates{
Data: map[string]any{
"foo": "bar",
"hello": "$.vcsomething.something",
},
},
Data: issuing.ClaimTemplates{
"foo": "bar",
"hello": "$.vcsomething.something",
},
Expiry: issuing.TimeLike{
Time: &now,
Expand All @@ -226,13 +202,9 @@ func TestIssuanceRouter(t *testing.T) {
{
ID: "output_descriptor_1",
Schema: createdSchema.ID,
Data: issuing.CredentialTemplateData{
Claims: issuing.ClaimTemplates{
Data: map[string]any{
"foo": "bar",
"hello": "$.vcsomething.something",
},
},
Data: issuing.ClaimTemplates{
"foo": "bar",
"hello": "$.vcsomething.something",
},
Expiry: issuing.TimeLike{
Time: &now,
Expand Down Expand Up @@ -269,13 +241,9 @@ func TestIssuanceRouter(t *testing.T) {
{
ID: "output_descriptor_1",
Schema: createdSchema.Schema.ID,
Data: issuing.CredentialTemplateData{
Claims: issuing.ClaimTemplates{
Data: map[string]any{
"foo": "bar",
"hello": "$.vcsomething.something",
},
},
Data: issuing.ClaimTemplates{
"foo": "bar",
"hello": "$.vcsomething.something",
},
Expiry: issuing.TimeLike{
Time: &now,
Expand Down Expand Up @@ -391,13 +359,9 @@ func createSimpleTemplate(t *testing.T, manifest *model.CreateManifestResponse,
{
ID: "output_descriptor_1",
Schema: createdSchema.Schema.ID,
Data: issuing.CredentialTemplateData{
Claims: issuing.ClaimTemplates{
Data: map[string]any{
"foo": "bar",
"hello": "$.vcsomething.something",
},
},
Data: issuing.ClaimTemplates{
"foo": "bar",
"hello": "$.vcsomething.something",
},
Expiry: issuing.TimeLike{
Time: &now,
Expand Down
40 changes: 16 additions & 24 deletions pkg/server/server_manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1083,36 +1083,28 @@ func getValidIssuanceTemplateRequest(m manifest.CredentialManifest, issuerDID *d
Issuer: issuerDID.DID.ID,
Credentials: []issuing.CredentialTemplate{
{
ID: "id1",
Schema: createdSchema.ID,
Data: issuing.CredentialTemplateData{
CredentialInputDescriptor: "test-id",
Claims: issuing.ClaimTemplates{
Data: map[string]any{
"firstName": "$.credentialSubject.firstName",
"lastName": "$.credentialSubject.lastName",
"state": "CA",
},
},
ID: "id1",
Schema: createdSchema.ID,
CredentialInputDescriptor: "test-id",
Data: issuing.ClaimTemplates{
"firstName": "$.credentialSubject.firstName",
"lastName": "$.credentialSubject.lastName",
"state": "CA",
},
Expiry: issuing.TimeLike{
Time: &now,
},
},
{
ID: "id2",
Schema: createdSchema.ID,
Data: issuing.CredentialTemplateData{
CredentialInputDescriptor: "test-id",
Claims: issuing.ClaimTemplates{
Data: map[string]any{
"someCrazyObject": map[string]any{
"foo": 123,
"bar": false,
"baz": []any{
"yay", 123, nil,
},
},
ID: "id2",
Schema: createdSchema.ID,
CredentialInputDescriptor: "test-id",
Data: issuing.ClaimTemplates{
"someCrazyObject": map[string]any{
"foo": 123,
"bar": false,
"baz": []any{
"yay", 123, nil,
},
},
},
Expand Down
Loading

0 comments on commit 46abf9a

Please sign in to comment.