diff --git a/internal/keyaccess/dataintegrity_test.go b/internal/keyaccess/dataintegrity_test.go index 7a8db664b..9025f1b98 100644 --- a/internal/keyaccess/dataintegrity_test.go +++ b/internal/keyaccess/dataintegrity_test.go @@ -10,112 +10,112 @@ import ( ) func TestCreateDataIntegrityKeyAccess(t *testing.T) { - t.Run("Create a Key Access object - Happy Path", func(tt *testing.T) { + t.Run("Create a Key Access object - Happy Path", func(t *testing.T) { _, privKey, err := crypto.GenerateEd25519Key() id := "test-id" kid := "test-kid" - assert.NoError(tt, err) + assert.NoError(t, err) ka, err := NewDataIntegrityKeyAccess(id, kid, privKey) - assert.NoError(tt, err) - assert.NotEmpty(tt, ka) + assert.NoError(t, err) + assert.NotEmpty(t, ka) }) - t.Run("Create a Key Access object - Bad Key", func(tt *testing.T) { + t.Run("Create a Key Access object - Bad Key", func(t *testing.T) { id := "test-id" kid := "test-kid" ka, err := NewDataIntegrityKeyAccess(id, kid, nil) - assert.Error(tt, err) - assert.Contains(tt, err.Error(), "key cannot be nil") - assert.Empty(tt, ka) + assert.Error(t, err) + assert.Contains(t, err.Error(), "key cannot be nil") + assert.Empty(t, ka) }) - t.Run("Create a Key Access object - No KID", func(tt *testing.T) { + t.Run("Create a Key Access object - No KID", func(t *testing.T) { _, privKey, err := crypto.GenerateEd25519Key() - assert.NoError(tt, err) + assert.NoError(t, err) ka, err := NewDataIntegrityKeyAccess("test-id", "", privKey) - assert.Error(tt, err) - assert.Contains(tt, err.Error(), "kid cannot be empty") - assert.Empty(tt, ka) + assert.Error(t, err) + assert.Contains(t, err.Error(), "kid cannot be empty") + assert.Empty(t, ka) }) } func TestDataIntegrityKeyAccessSignVerify(t *testing.T) { - t.Run("Sign and Verify Credential - Happy Path", func(tt *testing.T) { + t.Run("Sign and Verify Credential - Happy Path", func(t *testing.T) { _, privKey, err := crypto.GenerateEd25519Key() id := "test-id" kid := "test-kid" - assert.NoError(tt, err) + assert.NoError(t, err) ka, err := NewDataIntegrityKeyAccess(id, kid, privKey) - assert.NoError(tt, err) - assert.NotEmpty(tt, ka) + assert.NoError(t, err) + assert.NotEmpty(t, ka) // sign testCred := getTestCredential(id) signedCred, err := ka.Sign(&testCred) - assert.NoError(tt, err) - assert.NotEmpty(tt, signedCred) + assert.NoError(t, err) + assert.NotEmpty(t, signedCred) var cred credential.VerifiableCredential err = json.Unmarshal(signedCred.Data, &cred) - assert.NoError(tt, err) + assert.NoError(t, err) // verify err = ka.Verify(&cred) - assert.NoError(tt, err) + assert.NoError(t, err) }) - t.Run("Sign and Verify Credential - Bad Data", func(tt *testing.T) { + t.Run("Sign and Verify Credential - Bad Data", func(t *testing.T) { _, privKey, err := crypto.GenerateEd25519Key() id := "test-id" kid := "test-kid" - assert.NoError(tt, err) + assert.NoError(t, err) ka, err := NewDataIntegrityKeyAccess(id, kid, privKey) - assert.NoError(tt, err) - assert.NotEmpty(tt, ka) + assert.NoError(t, err) + assert.NotEmpty(t, ka) // sign _, err = ka.Sign(nil) - assert.Error(tt, err) - assert.Contains(tt, err.Error(), "payload cannot be nil") + assert.Error(t, err) + assert.Contains(t, err.Error(), "payload cannot be nil") }) - t.Run("Sign and Verify Credential - Bad Signature", func(tt *testing.T) { + t.Run("Sign and Verify Credential - Bad Signature", func(t *testing.T) { _, privKey, err := crypto.GenerateEd25519Key() id := "test-id" kid := "test-kid" - assert.NoError(tt, err) + assert.NoError(t, err) ka, err := NewDataIntegrityKeyAccess(id, kid, privKey) - assert.NoError(tt, err) - assert.NotEmpty(tt, ka) + assert.NoError(t, err) + assert.NotEmpty(t, ka) // verify err = ka.Verify(nil) - assert.Error(tt, err) - assert.Contains(tt, err.Error(), "payload cannot be nil") + assert.Error(t, err) + assert.Contains(t, err.Error(), "payload cannot be nil") }) - t.Run("Sign and Verify Presentation", func(tt *testing.T) { + t.Run("Sign and Verify Presentation", func(t *testing.T) { _, privKey, err := crypto.GenerateEd25519Key() id := "test-id" kid := "test-kid" - assert.NoError(tt, err) + assert.NoError(t, err) ka, err := NewDataIntegrityKeyAccess(id, kid, privKey) - assert.NoError(tt, err) - assert.NotEmpty(tt, ka) + assert.NoError(t, err) + assert.NotEmpty(t, ka) // sign testPres := getDataIntegrityTestPresentation(*ka) signedPres, err := ka.Sign(&testPres) - assert.NoError(tt, err) - assert.NotEmpty(tt, signedPres) + assert.NoError(t, err) + assert.NotEmpty(t, signedPres) var pres credential.VerifiablePresentation err = json.Unmarshal(signedPres.Data, &pres) - assert.NoError(tt, err) + assert.NoError(t, err) // verify err = ka.Verify(&pres) - assert.NoError(tt, err) + assert.NoError(t, err) // TODO(gabe) enable with https://github.com/TBD54566975/ssi-sdk/issues/352, https://github.com/TBD54566975/ssi-service/issues/105 err = ka.VerifyVerifiablePresentation(&pres) diff --git a/internal/keyaccess/jwt_test.go b/internal/keyaccess/jwt_test.go index 7dfd1212e..d3520e90c 100644 --- a/internal/keyaccess/jwt_test.go +++ b/internal/keyaccess/jwt_test.go @@ -68,222 +68,222 @@ func TestJWKKeyAccessForEachKeyType(t *testing.T) { } func TestCreateJWKKeyAccess(t *testing.T) { - t.Run("Create a Key Access object - Happy Path", func(tt *testing.T) { + t.Run("Create a Key Access object - Happy Path", func(t *testing.T) { _, privKey, err := crypto.GenerateEd25519Key() testID := "test-id" kid := "test-kid" - assert.NoError(tt, err) + assert.NoError(t, err) ka, err := NewJWKKeyAccess(testID, kid, privKey) - assert.NoError(tt, err) - assert.NotEmpty(tt, ka) + assert.NoError(t, err) + assert.NotEmpty(t, ka) }) - t.Run("Create a Key Access object - Bad Key", func(tt *testing.T) { + t.Run("Create a Key Access object - Bad Key", func(t *testing.T) { testID := "test-id" kid := "test-kid" ka, err := NewJWKKeyAccess(testID, kid, nil) - assert.Error(tt, err) - assert.Contains(tt, err.Error(), "key cannot be nil") - assert.Empty(tt, ka) + assert.Error(t, err) + assert.Contains(t, err.Error(), "key cannot be nil") + assert.Empty(t, ka) }) - t.Run("Create a Key Access object - No KID", func(tt *testing.T) { + t.Run("Create a Key Access object - No KID", func(t *testing.T) { _, privKey, err := crypto.GenerateEd25519Key() - assert.NoError(tt, err) + assert.NoError(t, err) ka, err := NewJWKKeyAccess("test-id", "", privKey) - assert.Error(tt, err) - assert.Contains(tt, err.Error(), "kid cannot be empty") - assert.Empty(tt, ka) + assert.Error(t, err) + assert.Contains(t, err.Error(), "kid cannot be empty") + assert.Empty(t, ka) }) } func TestJWKKeyAccessSignVerify(t *testing.T) { - t.Run("Sign and Verify - Happy Path", func(tt *testing.T) { + t.Run("Sign and Verify - Happy Path", func(t *testing.T) { _, privKey, err := crypto.GenerateEd25519Key() testID := "test-id" kid := "test-kid" - assert.NoError(tt, err) + assert.NoError(t, err) ka, err := NewJWKKeyAccess(testID, kid, privKey) - assert.NoError(tt, err) - assert.NotEmpty(tt, ka) + assert.NoError(t, err) + assert.NotEmpty(t, ka) data := map[string]any{ "test": "test", } token, err := ka.Sign(data) - assert.NoError(tt, err) - assert.NotEmpty(tt, token) + assert.NoError(t, err) + assert.NotEmpty(t, token) err = ka.Verify(*token) - assert.NoError(tt, err) + assert.NoError(t, err) // Create just a verifier and check that it can verify the token verifier, err := NewJWKKeyAccessVerifier(testID, kid, privKey.Public()) - assert.NoError(tt, err) - assert.NotEmpty(tt, verifier) + assert.NoError(t, err) + assert.NotEmpty(t, verifier) err = verifier.Verify(*token) - assert.NoError(tt, err) + assert.NoError(t, err) // Make sure the verifier can't sign _, err = verifier.Sign(data) - assert.Error(tt, err) - assert.Contains(tt, err.Error(), "cannot sign with nil signer") + assert.Error(t, err) + assert.Contains(t, err.Error(), "cannot sign with nil signer") }) - t.Run("Sign and Verify - Bad Data", func(tt *testing.T) { + t.Run("Sign and Verify - Bad Data", func(t *testing.T) { _, privKey, err := crypto.GenerateEd25519Key() testID := "test-id" kid := "test-kid" - assert.NoError(tt, err) + assert.NoError(t, err) ka, err := NewJWKKeyAccess(testID, kid, privKey) - assert.NoError(tt, err) - assert.NotEmpty(tt, ka) + assert.NoError(t, err) + assert.NotEmpty(t, ka) _, err = ka.Sign(nil) - assert.Error(tt, err) - assert.Contains(tt, err.Error(), "payload cannot be nil") + assert.Error(t, err) + assert.Contains(t, err.Error(), "payload cannot be nil") }) - t.Run("Sign and Verify - Bad Signature", func(tt *testing.T) { + t.Run("Sign and Verify - Bad Signature", func(t *testing.T) { _, privKey, err := crypto.GenerateEd25519Key() testID := "test-id" kid := "test-kid" - assert.NoError(tt, err) + assert.NoError(t, err) ka, err := NewJWKKeyAccess(testID, kid, privKey) - assert.NoError(tt, err) - assert.NotEmpty(tt, ka) + assert.NoError(t, err) + assert.NotEmpty(t, ka) err = ka.Verify(JWT("")) - assert.Error(tt, err) - assert.Contains(tt, err.Error(), "token cannot be empty") + assert.Error(t, err) + assert.Contains(t, err.Error(), "token cannot be empty") }) } func TestJWKKeyAccessSignVerifyCredentials(t *testing.T) { - t.Run("Sign and Verify Credentials - Happy Path", func(tt *testing.T) { + t.Run("Sign and Verify Credentials - Happy Path", func(t *testing.T) { _, privKey, err := crypto.GenerateEd25519Key() testID := "test-id" kid := "test-kid" - assert.NoError(tt, err) + assert.NoError(t, err) ka, err := NewJWKKeyAccess(testID, kid, privKey) - assert.NoError(tt, err) - assert.NotEmpty(tt, ka) + assert.NoError(t, err) + assert.NotEmpty(t, ka) // sign testCred := getTestCredential(testID) testCredCopy := copyCred(t, testCred) signedCred, err := ka.SignVerifiableCredential(testCredCopy) - assert.NoError(tt, err) - assert.NotEmpty(tt, signedCred) + assert.NoError(t, err) + assert.NotEmpty(t, signedCred) // verify verifiedCred, err := ka.VerifyVerifiableCredential(*signedCred) - assert.NoError(tt, err) - assert.NotEmpty(tt, verifiedCred) + assert.NoError(t, err) + assert.NotEmpty(t, verifiedCred) // check equality testJSON, err := json.Marshal(testCred) - assert.NoError(tt, err) + assert.NoError(t, err) verifiedJSON, err := json.Marshal(verifiedCred) - assert.NoError(tt, err) - assert.JSONEq(tt, string(testJSON), string(verifiedJSON)) + assert.NoError(t, err) + assert.JSONEq(t, string(testJSON), string(verifiedJSON)) }) - t.Run("Sign and Verify Credentials - Bad Data", func(tt *testing.T) { + t.Run("Sign and Verify Credentials - Bad Data", func(t *testing.T) { _, privKey, err := crypto.GenerateEd25519Key() testID := "test-id" kid := "test-kid" - assert.NoError(tt, err) + assert.NoError(t, err) ka, err := NewJWKKeyAccess(testID, kid, privKey) - assert.NoError(tt, err) - assert.NotEmpty(tt, ka) + assert.NoError(t, err) + assert.NotEmpty(t, ka) // sign _, err = ka.SignVerifiableCredential(credential.VerifiableCredential{}) - assert.Error(tt, err) - assert.Contains(tt, err.Error(), "cannot sign invalid credential") + assert.Error(t, err) + assert.Contains(t, err.Error(), "cannot sign invalid credential") }) - t.Run("Sign and Verify Credentials - Bad Signature", func(tt *testing.T) { + t.Run("Sign and Verify Credentials - Bad Signature", func(t *testing.T) { _, privKey, err := crypto.GenerateEd25519Key() testID := "test-id" kid := "test-kid" - assert.NoError(tt, err) + assert.NoError(t, err) ka, err := NewJWKKeyAccess(testID, kid, privKey) - assert.NoError(tt, err) - assert.NotEmpty(tt, ka) + assert.NoError(t, err) + assert.NotEmpty(t, ka) // verify _, err = ka.VerifyVerifiableCredential("bad") - assert.Error(tt, err) - assert.Contains(tt, err.Error(), "invalid JWT") + assert.Error(t, err) + assert.Contains(t, err.Error(), "invalid JWT") }) } func TestJWKKeyAccessSignVerifyPresentations(t *testing.T) { - t.Run("Sign and Verify Presentations - Happy Path", func(tt *testing.T) { + t.Run("Sign and Verify Presentations - Happy Path", func(t *testing.T) { privKey, didKey, err := key.GenerateDIDKey(crypto.Ed25519) - assert.NoError(tt, err) - assert.NotEmpty(tt, privKey) + assert.NoError(t, err) + assert.NotEmpty(t, privKey) expanded, err := didKey.Expand() - assert.NoError(tt, err) + assert.NoError(t, err) kid := expanded.VerificationMethod[0].ID ka, err := NewJWKKeyAccess(didKey.String(), kid, privKey) - assert.NoError(tt, err) - assert.NotEmpty(tt, ka) + assert.NoError(t, err) + assert.NotEmpty(t, ka) // sign testPres := getJWTTestPresentation(*ka) signedPres, err := ka.SignVerifiablePresentation(didKey.String(), testPres) - assert.NoError(tt, err) - assert.NotEmpty(tt, signedPres) + assert.NoError(t, err) + assert.NotEmpty(t, signedPres) // verify resolver, err := resolution.NewResolver([]resolution.Resolver{key.Resolver{}}...) - assert.NoError(tt, err) + assert.NoError(t, err) verifiedPres, err := ka.VerifyVerifiablePresentation(context.Background(), resolver, *signedPres) - assert.NoError(tt, err) - assert.NotEmpty(tt, verifiedPres) + assert.NoError(t, err) + assert.NotEmpty(t, verifiedPres) // check equality testJSON, err := json.Marshal(testPres) - assert.NoError(tt, err) + assert.NoError(t, err) verifiedJSON, err := json.Marshal(verifiedPres) - assert.NoError(tt, err) - assert.JSONEq(tt, string(testJSON), string(verifiedJSON)) + assert.NoError(t, err) + assert.JSONEq(t, string(testJSON), string(verifiedJSON)) }) - t.Run("Sign and Verify Presentations - Bad Data", func(tt *testing.T) { + t.Run("Sign and Verify Presentations - Bad Data", func(t *testing.T) { _, privKey, err := crypto.GenerateEd25519Key() testID := "test-id" kid := "test-kid" - assert.NoError(tt, err) + assert.NoError(t, err) ka, err := NewJWKKeyAccess(testID, kid, privKey) - assert.NoError(tt, err) - assert.NotEmpty(tt, ka) + assert.NoError(t, err) + assert.NotEmpty(t, ka) // sign _, err = ka.SignVerifiablePresentation("test-audience", credential.VerifiablePresentation{}) - assert.Error(tt, err) - assert.Contains(tt, err.Error(), "cannot sign invalid presentation") + assert.Error(t, err) + assert.Contains(t, err.Error(), "cannot sign invalid presentation") }) - t.Run("Sign and Verify Presentations - Bad Signature", func(tt *testing.T) { + t.Run("Sign and Verify Presentations - Bad Signature", func(t *testing.T) { _, privKey, err := crypto.GenerateEd25519Key() testID := "test-id" kid := "test-kid" - assert.NoError(tt, err) + assert.NoError(t, err) ka, err := NewJWKKeyAccess(testID, kid, privKey) - assert.NoError(tt, err) - assert.NotEmpty(tt, ka) + assert.NoError(t, err) + assert.NotEmpty(t, ka) // verify resolver, err := resolution.NewResolver([]resolution.Resolver{key.Resolver{}}...) - assert.NoError(tt, err) + assert.NoError(t, err) _, err = ka.VerifyVerifiablePresentation(context.Background(), resolver, "bad") - assert.Error(tt, err) - assert.Contains(tt, err.Error(), "invalid JWT") + assert.Error(t, err) + assert.Contains(t, err.Error(), "invalid JWT") }) } diff --git a/pkg/server/router/credential_test.go b/pkg/server/router/credential_test.go index 1642f9025..b5a11c616 100644 --- a/pkg/server/router/credential_test.go +++ b/pkg/server/router/credential_test.go @@ -30,41 +30,41 @@ func TestCredentialRouter(t *testing.T) { for _, test := range testutil.TestDatabases { t.Run(test.Name, func(t *testing.T) { - t.Run("Nil Service", func(tt *testing.T) { + t.Run("Nil Service", func(t *testing.T) { credRouter, err := NewCredentialRouter(nil) - assert.Error(tt, err) - assert.Empty(tt, credRouter) - assert.Contains(tt, err.Error(), "service cannot be nil") + assert.Error(t, err) + assert.Empty(t, credRouter) + assert.Contains(t, err.Error(), "service cannot be nil") }) - t.Run("Bad Service", func(tt *testing.T) { + t.Run("Bad Service", func(t *testing.T) { credRouter, err := NewCredentialRouter(&testService{}) - assert.Error(tt, err) - assert.Empty(tt, credRouter) - assert.Contains(tt, err.Error(), "could not create credential router with service type: test") + assert.Error(t, err) + assert.Empty(t, credRouter) + assert.Contains(t, err.Error(), "could not create credential router with service type: test") }) - t.Run("Credential Service Test", func(tt *testing.T) { - s := test.ServiceStorage(tt) - assert.NotEmpty(tt, s) + t.Run("Credential Service Test", func(t *testing.T) { + s := test.ServiceStorage(t) + assert.NotEmpty(t, s) serviceConfig := config.CredentialServiceConfig{BatchCreateMaxItems: 100} - keyStoreService := testKeyStoreService(tt, s) - didService := testDIDService(tt, s, keyStoreService) - schemaService := testSchemaService(tt, s, keyStoreService, didService) + keyStoreService := testKeyStoreService(t, s) + didService := testDIDService(t, s, keyStoreService) + schemaService := testSchemaService(t, s, keyStoreService, didService) credService, err := credential.NewCredentialService(serviceConfig, s, keyStoreService, didService.GetResolver(), schemaService) - assert.NoError(tt, err) - assert.NotEmpty(tt, credService) + assert.NoError(t, err) + assert.NotEmpty(t, credService) // check type and status - assert.Equal(tt, framework.Credential, credService.Type()) - assert.Equal(tt, framework.StatusReady, credService.Status().Status) + assert.Equal(t, framework.Credential, credService.Type()) + assert.Equal(t, framework.StatusReady, credService.Status().Status) // create a credential issuerDID, err := didService.CreateDIDByMethod(context.Background(), did.CreateDIDRequest{Method: didsdk.KeyMethod, KeyType: crypto.Ed25519}) - assert.NoError(tt, err) - assert.NotEmpty(tt, issuerDID) + assert.NoError(t, err) + assert.NotEmpty(t, issuerDID) issuer := issuerDID.DID.ID subject := "did:test:345" @@ -78,66 +78,66 @@ func TestCredentialRouter(t *testing.T) { }, Expiry: time.Now().Add(24 * time.Hour).Format(time.RFC3339), }) - assert.NoError(tt, err) - assert.NotEmpty(tt, createdCred) - assert.NotEmpty(tt, createdCred.CredentialJWT) - assert.Empty(tt, createdCred.Credential.Evidence) + assert.NoError(t, err) + assert.NotEmpty(t, createdCred) + assert.NotEmpty(t, createdCred.CredentialJWT) + assert.Empty(t, createdCred.Credential.Evidence) cred := createdCred.Credential // make sure it has the right data - assert.Equal(tt, issuer, cred.Issuer) - assert.Equal(tt, subject, cred.CredentialSubject[credsdk.VerifiableCredentialIDProperty]) - assert.Equal(tt, "Satoshi", cred.CredentialSubject["firstName"]) - assert.Equal(tt, "Nakamoto", cred.CredentialSubject["lastName"]) + assert.Equal(t, issuer, cred.Issuer) + assert.Equal(t, subject, cred.CredentialSubject[credsdk.VerifiableCredentialIDProperty]) + assert.Equal(t, "Satoshi", cred.CredentialSubject["firstName"]) + assert.Equal(t, "Nakamoto", cred.CredentialSubject["lastName"]) // get it back gotCred, err := credService.GetCredential(context.Background(), credential.GetCredentialRequest{ID: idFromURI(cred.ID)}) - assert.NoError(tt, err) - assert.NotEmpty(tt, gotCred) + assert.NoError(t, err) + assert.NotEmpty(t, gotCred) // compare for object equality - assert.Equal(tt, createdCred.CredentialJWT, gotCred.CredentialJWT) + assert.Equal(t, createdCred.CredentialJWT, gotCred.CredentialJWT) // verify it verified, err := credService.VerifyCredential(context.Background(), credential.VerifyCredentialRequest{CredentialJWT: gotCred.CredentialJWT}) - assert.NoError(tt, err) - assert.True(tt, verified.Verified) + assert.NoError(t, err) + assert.True(t, verified.Verified) // get a cred that doesn't exist _, err = credService.GetCredential(context.Background(), credential.GetCredentialRequest{ID: "bad"}) - assert.Error(tt, err) - assert.Contains(tt, err.Error(), "credential not found with id: bad") + assert.Error(t, err) + assert.Contains(t, err.Error(), "credential not found with id: bad") // get by schema - no schema sch := "" filter, err := filtering.ParseFilter(listCredentialsRequest{schema: &sch}, listCredentialsFilterDeclarations) - assert.NoError(tt, err) + assert.NoError(t, err) bySchema, err := credService.ListCredentials(context.Background(), filter, pagination.PageRequest{}) - assert.NoError(tt, err) - assert.Len(tt, bySchema.Credentials, 1) - assert.EqualValues(tt, cred.CredentialSchema, bySchema.Credentials[0].Credential.CredentialSchema) + assert.NoError(t, err) + assert.Len(t, bySchema.Credentials, 1) + assert.EqualValues(t, cred.CredentialSchema, bySchema.Credentials[0].Credential.CredentialSchema) // get by subject filter, err = filtering.ParseFilter(listCredentialsRequest{subject: &subject}, listCredentialsFilterDeclarations) - assert.NoError(tt, err) + assert.NoError(t, err) bySubject, err := credService.ListCredentials(context.Background(), filter, pagination.PageRequest{}) - assert.NoError(tt, err) - assert.Len(tt, bySubject.Credentials, 1) + assert.NoError(t, err) + assert.Len(t, bySubject.Credentials, 1) - assert.Equal(tt, createdCred.ID, bySubject.Credentials[0].ID) - assert.Equal(tt, cred.ID, bySubject.Credentials[0].Credential.ID) - assert.Equal(tt, cred.CredentialSubject[credsdk.VerifiableCredentialIDProperty], bySubject.Credentials[0].Credential.CredentialSubject[credsdk.VerifiableCredentialIDProperty]) + assert.Equal(t, createdCred.ID, bySubject.Credentials[0].ID) + assert.Equal(t, cred.ID, bySubject.Credentials[0].Credential.ID) + assert.Equal(t, cred.CredentialSubject[credsdk.VerifiableCredentialIDProperty], bySubject.Credentials[0].Credential.CredentialSubject[credsdk.VerifiableCredentialIDProperty]) // get by issuer filter, err = filtering.ParseFilter(listCredentialsRequest{issuer: &issuer}, listCredentialsFilterDeclarations) - assert.NoError(tt, err) + assert.NoError(t, err) byIssuer, err := credService.ListCredentials(context.Background(), filter, pagination.PageRequest{}) - assert.NoError(tt, err) - assert.Len(tt, byIssuer.Credentials, 1) + assert.NoError(t, err) + assert.Len(t, byIssuer.Credentials, 1) - assert.Equal(tt, cred.ID, byIssuer.Credentials[0].Credential.ID) - assert.Equal(tt, cred.Issuer, byIssuer.Credentials[0].Credential.Issuer) + assert.Equal(t, cred.ID, byIssuer.Credentials[0].Credential.ID) + assert.Equal(t, cred.Issuer, byIssuer.Credentials[0].Credential.Issuer) // create another cred with the same issuer, different subject, different schema that doesn't exist _, err = credService.CreateCredential(context.Background(), credential.CreateCredentialRequest{ @@ -150,13 +150,13 @@ func TestCredentialRouter(t *testing.T) { }, Expiry: time.Now().Add(24 * time.Hour).Format(time.RFC3339), }) - assert.Error(tt, err) - assert.Contains(tt, err.Error(), "schema not found with id: https://test-schema.com") + assert.Error(t, err) + assert.Contains(t, err.Error(), "schema not found with id: https://test-schema.com") // create schema createdSchema, err := schemaService.CreateSchema(context.Background(), schema.CreateSchemaRequest{Issuer: issuerDID.DID.ID, Name: "simple schema", Schema: getEmailSchema()}) - assert.NoError(tt, err) - assert.NotEmpty(tt, createdSchema) + assert.NoError(t, err) + assert.NotEmpty(t, createdSchema) // create another cred with the same issuer, different subject, different schema that does exist createdCredWithSchema, err := credService.CreateCredential(context.Background(), credential.CreateCredentialRequest{ @@ -169,66 +169,66 @@ func TestCredentialRouter(t *testing.T) { }, Expiry: time.Now().Add(24 * time.Hour).Format(time.RFC3339), }) - assert.NoError(tt, err) - assert.NotEmpty(tt, createdCredWithSchema) + assert.NoError(t, err) + assert.NotEmpty(t, createdCredWithSchema) // get by issuer byIssuer, err = credService.ListCredentials(context.Background(), filter, pagination.PageRequest{}) - assert.NoError(tt, err) - assert.Len(tt, byIssuer.Credentials, 2) + assert.NoError(t, err) + assert.Len(t, byIssuer.Credentials, 2) // make sure the schema and subject queries are consistent filter, err = filtering.ParseFilter(listCredentialsRequest{schema: &sch}, listCredentialsFilterDeclarations) - assert.NoError(tt, err) + assert.NoError(t, err) bySchema, err = credService.ListCredentials(context.Background(), filter, pagination.PageRequest{}) - assert.NoError(tt, err) - assert.Len(tt, bySchema.Credentials, 1) + assert.NoError(t, err) + assert.Len(t, bySchema.Credentials, 1) - assert.Equal(tt, createdCred.ID, bySchema.Credentials[0].ID) - assert.Equal(tt, cred.ID, bySchema.Credentials[0].Credential.ID) - assert.EqualValues(tt, cred.CredentialSchema, bySchema.Credentials[0].Credential.CredentialSchema) + assert.Equal(t, createdCred.ID, bySchema.Credentials[0].ID) + assert.Equal(t, cred.ID, bySchema.Credentials[0].Credential.ID) + assert.EqualValues(t, cred.CredentialSchema, bySchema.Credentials[0].Credential.CredentialSchema) filter, err = filtering.ParseFilter(listCredentialsRequest{subject: &subject}, listCredentialsFilterDeclarations) - assert.NoError(tt, err) + assert.NoError(t, err) bySubject, err = credService.ListCredentials(context.Background(), filter, pagination.PageRequest{}) - assert.NoError(tt, err) - assert.Len(tt, bySubject.Credentials, 1) + assert.NoError(t, err) + assert.Len(t, bySubject.Credentials, 1) - assert.Equal(tt, createdCred.ID, bySubject.Credentials[0].ID) - assert.Equal(tt, cred.ID, bySubject.Credentials[0].Credential.ID) - assert.Equal(tt, cred.CredentialSubject[credsdk.VerifiableCredentialIDProperty], bySubject.Credentials[0].Credential.CredentialSubject[credsdk.VerifiableCredentialIDProperty]) + assert.Equal(t, createdCred.ID, bySubject.Credentials[0].ID) + assert.Equal(t, cred.ID, bySubject.Credentials[0].Credential.ID) + assert.Equal(t, cred.CredentialSubject[credsdk.VerifiableCredentialIDProperty], bySubject.Credentials[0].Credential.CredentialSubject[credsdk.VerifiableCredentialIDProperty]) // delete a cred that doesn't exist (no error since idempotent) err = credService.DeleteCredential(context.Background(), credential.DeleteCredentialRequest{ID: "bad"}) - assert.NoError(tt, err) + assert.NoError(t, err) // delete a credential that does exist err = credService.DeleteCredential(context.Background(), credential.DeleteCredentialRequest{ID: cred.ID}) - assert.NoError(tt, err) + assert.NoError(t, err) // get it back _, err = credService.GetCredential(context.Background(), credential.GetCredentialRequest{ID: cred.ID}) - assert.Error(tt, err) - assert.Contains(tt, err.Error(), fmt.Sprintf("credential not found with id: %s", cred.ID)) + assert.Error(t, err) + assert.Contains(t, err.Error(), fmt.Sprintf("credential not found with id: %s", cred.ID)) }) - t.Run("Credential Service Test Revoked Key", func(tt *testing.T) { - s := test.ServiceStorage(tt) - assert.NotEmpty(tt, s) + t.Run("Credential Service Test Revoked Key", func(t *testing.T) { + s := test.ServiceStorage(t) + assert.NotEmpty(t, s) // Initialize services serviceConfig := config.CredentialServiceConfig{BatchCreateMaxItems: 100} - keyStoreService := testKeyStoreService(tt, s) - didService := testDIDService(tt, s, keyStoreService) - schemaService := testSchemaService(tt, s, keyStoreService, didService) + keyStoreService := testKeyStoreService(t, s) + didService := testDIDService(t, s, keyStoreService) + schemaService := testSchemaService(t, s, keyStoreService, didService) credService, err := credential.NewCredentialService(serviceConfig, s, keyStoreService, didService.GetResolver(), schemaService) - assert.NoError(tt, err) - assert.NotEmpty(tt, credService) + assert.NoError(t, err) + assert.NotEmpty(t, credService) // Create a DID controllerDID, err := didService.CreateDIDByMethod(context.Background(), did.CreateDIDRequest{Method: didsdk.KeyMethod, KeyType: crypto.Ed25519}) - assert.NoError(tt, err) - assert.NotEmpty(tt, controllerDID) + assert.NoError(t, err) + assert.NotEmpty(t, controllerDID) didID := controllerDID.DID.ID // Create a key controlled by the DID @@ -236,7 +236,7 @@ func TestCredentialRouter(t *testing.T) { privateKey := "2dEPd7mA3aiuh2gky8tTPiCkyMwf8tBNUMZwRzeVxVJnJFGTbdLGUBcx51DCNyFWRjTG9bduvyLRStXSCDMFXULY" err = keyStoreService.StoreKey(context.Background(), keystore.StoreKeyRequest{ID: keyID, Type: crypto.Ed25519, Controller: didID, PrivateKeyBase58: privateKey}) - assert.NoError(tt, err) + assert.NoError(t, err) // Create a crendential subject := "did:test:42" @@ -250,13 +250,13 @@ func TestCredentialRouter(t *testing.T) { }, Expiry: time.Now().Add(24 * time.Hour).Format(time.RFC3339), }) - assert.NoError(tt, err) - assert.NotEmpty(tt, createdCred) - assert.NotEmpty(tt, createdCred.CredentialJWT) + assert.NoError(t, err) + assert.NotEmpty(t, createdCred) + assert.NotEmpty(t, createdCred.CredentialJWT) // Revoke the key err = keyStoreService.RevokeKey(context.Background(), keystore.RevokeKeyRequest{ID: keyID}) - assert.NoError(tt, err) + assert.NoError(t, err) // Create a credential with the revoked key, it fails subject = "did:test:43" @@ -270,36 +270,36 @@ func TestCredentialRouter(t *testing.T) { }, Expiry: time.Now().Add(24 * time.Hour).Format(time.RFC3339), }) - assert.Empty(tt, createdCred) - assert.Error(tt, err) - assert.ErrorContains(tt, err, "cannot use revoked key") + assert.Empty(t, createdCred) + assert.Error(t, err) + assert.ErrorContains(t, err, "cannot use revoked key") }) - t.Run("Credential Status List Test", func(tt *testing.T) { - s := test.ServiceStorage(tt) - assert.NotEmpty(tt, s) + t.Run("Credential Status List Test", func(t *testing.T) { + s := test.ServiceStorage(t) + assert.NotEmpty(t, s) serviceConfig := config.CredentialServiceConfig{BatchCreateMaxItems: 100} - keyStoreService := testKeyStoreService(tt, s) - didService := testDIDService(tt, s, keyStoreService) - schemaService := testSchemaService(tt, s, keyStoreService, didService) + keyStoreService := testKeyStoreService(t, s) + didService := testDIDService(t, s, keyStoreService) + schemaService := testSchemaService(t, s, keyStoreService, didService) credService, err := credential.NewCredentialService(serviceConfig, s, keyStoreService, didService.GetResolver(), schemaService) - assert.NoError(tt, err) - assert.NotEmpty(tt, credService) + assert.NoError(t, err) + assert.NotEmpty(t, credService) // check type and status - assert.Equal(tt, framework.Credential, credService.Type()) - assert.Equal(tt, framework.StatusReady, credService.Status().Status) + assert.Equal(t, framework.Credential, credService.Type()) + assert.Equal(t, framework.StatusReady, credService.Status().Status) // create a did issuerDID, err := didService.CreateDIDByMethod(context.Background(), did.CreateDIDRequest{Method: didsdk.KeyMethod, KeyType: crypto.Ed25519}) - assert.NoError(tt, err) - assert.NotEmpty(tt, issuerDID) + assert.NoError(t, err) + assert.NotEmpty(t, issuerDID) // create a schema createdSchema, err := schemaService.CreateSchema(context.Background(), schema.CreateSchemaRequest{Issuer: issuerDID.DID.ID, Name: "simple schema", Schema: getEmailSchema()}) - assert.NoError(tt, err) - assert.NotEmpty(tt, createdSchema) + assert.NoError(t, err) + assert.NotEmpty(t, createdSchema) issuer := issuerDID.DID.ID subject := "did:test:345" @@ -316,16 +316,16 @@ func TestCredentialRouter(t *testing.T) { Revocable: true, }) - assert.NoError(tt, err) - assert.NotEmpty(tt, createdCredResp) - assert.NotEmpty(tt, createdCredResp.CredentialJWT) + assert.NoError(t, err) + assert.NotEmpty(t, createdCredResp) + assert.NotEmpty(t, createdCredResp.CredentialJWT) credStatusMap, ok := createdCredResp.Credential.CredentialStatus.(map[string]any) - assert.True(tt, ok) + assert.True(t, ok) - assert.Equal(tt, credStatusMap["id"], createdCredResp.Credential.ID+"/status") - assert.Contains(tt, credStatusMap["statusListCredential"], "v1/credentials/status") - assert.NotEmpty(tt, credStatusMap["statusListIndex"]) + assert.Equal(t, credStatusMap["id"], createdCredResp.Credential.ID+"/status") + assert.Contains(t, credStatusMap["statusListCredential"], "v1/credentials/status") + assert.NotEmpty(t, credStatusMap["statusListIndex"]) createdCredRespTwo, err := credService.CreateCredential(context.Background(), credential.CreateCredentialRequest{ Issuer: issuer, @@ -339,23 +339,23 @@ func TestCredentialRouter(t *testing.T) { Revocable: true, }) - assert.NoError(tt, err) - assert.NotEmpty(tt, createdCredRespTwo) - assert.NotEmpty(tt, createdCredRespTwo.CredentialJWT) + assert.NoError(t, err) + assert.NotEmpty(t, createdCredRespTwo) + assert.NotEmpty(t, createdCredRespTwo.CredentialJWT) credStatusMapTwo, ok := createdCredRespTwo.Credential.CredentialStatus.(map[string]any) - assert.True(tt, ok) + assert.True(t, ok) - assert.Equal(tt, credStatusMapTwo["id"], createdCredRespTwo.Credential.ID+"/status") - assert.Contains(tt, credStatusMapTwo["statusListCredential"], "v1/credentials/status") - assert.NotEmpty(tt, credStatusMapTwo["statusListIndex"]) + assert.Equal(t, credStatusMapTwo["id"], createdCredRespTwo.Credential.ID+"/status") + assert.Contains(t, credStatusMapTwo["statusListCredential"], "v1/credentials/status") + assert.NotEmpty(t, credStatusMapTwo["statusListIndex"]) // Cred with same pair share the same statusListCredential - assert.Equal(tt, credStatusMapTwo["statusListCredential"], credStatusMap["statusListCredential"]) + assert.Equal(t, credStatusMapTwo["statusListCredential"], credStatusMap["statusListCredential"]) createdSchemaTwo, err := schemaService.CreateSchema(context.Background(), schema.CreateSchemaRequest{Issuer: issuerDID.DID.ID, Name: "simple schema", Schema: getEmailSchema()}) - assert.NoError(tt, err) - assert.NotEmpty(tt, createdSchemaTwo) + assert.NoError(t, err) + assert.NotEmpty(t, createdSchemaTwo) createdCredRespThree, err := credService.CreateCredential(context.Background(), credential.CreateCredentialRequest{ Issuer: issuer, @@ -369,42 +369,42 @@ func TestCredentialRouter(t *testing.T) { Revocable: true, }) - assert.NoError(tt, err) - assert.NotEmpty(tt, createdCredRespThree) - assert.NotEmpty(tt, createdCredRespThree.CredentialJWT) + assert.NoError(t, err) + assert.NotEmpty(t, createdCredRespThree) + assert.NotEmpty(t, createdCredRespThree.CredentialJWT) credStatusMapThree, ok := createdCredRespThree.Credential.CredentialStatus.(map[string]any) - assert.True(tt, ok) + assert.True(t, ok) - assert.Contains(tt, credStatusMapThree["id"], createdCredRespThree.Credential.ID) - assert.Contains(tt, credStatusMapThree["statusListCredential"], "v1/credentials/status") - assert.NotEmpty(tt, credStatusMapThree["statusListIndex"]) + assert.Contains(t, credStatusMapThree["id"], createdCredRespThree.Credential.ID) + assert.Contains(t, credStatusMapThree["statusListCredential"], "v1/credentials/status") + assert.NotEmpty(t, credStatusMapThree["statusListIndex"]) // Cred with different pair have different statusListCredential - assert.NotEqual(tt, credStatusMapThree["statusListCredential"], credStatusMap["statusListCredential"]) + assert.NotEqual(t, credStatusMapThree["statusListCredential"], credStatusMap["statusListCredential"]) }) - t.Run("Credential Status List Test No Schemas", func(tt *testing.T) { - s := test.ServiceStorage(tt) - assert.NotEmpty(tt, s) + t.Run("Credential Status List Test No Schemas", func(t *testing.T) { + s := test.ServiceStorage(t) + assert.NotEmpty(t, s) serviceConfig := config.CredentialServiceConfig{BatchCreateMaxItems: 100} - keyStoreService := testKeyStoreService(tt, s) - didService := testDIDService(tt, s, keyStoreService) - schemaService := testSchemaService(tt, s, keyStoreService, didService) + keyStoreService := testKeyStoreService(t, s) + didService := testDIDService(t, s, keyStoreService) + schemaService := testSchemaService(t, s, keyStoreService, didService) credService, err := credential.NewCredentialService(serviceConfig, s, keyStoreService, didService.GetResolver(), schemaService) - assert.NoError(tt, err) - assert.NotEmpty(tt, credService) + assert.NoError(t, err) + assert.NotEmpty(t, credService) // check type and status - assert.Equal(tt, framework.Credential, credService.Type()) - assert.Equal(tt, framework.StatusReady, credService.Status().Status) + assert.Equal(t, framework.Credential, credService.Type()) + assert.Equal(t, framework.StatusReady, credService.Status().Status) // create a did issuerDID, err := didService.CreateDIDByMethod(context.Background(), did.CreateDIDRequest{Method: didsdk.KeyMethod, KeyType: crypto.Ed25519}) - assert.NoError(tt, err) - assert.NotEmpty(tt, issuerDID) + assert.NoError(t, err) + assert.NotEmpty(t, issuerDID) issuer := issuerDID.DID.ID subject := "did:test:345" @@ -420,16 +420,16 @@ func TestCredentialRouter(t *testing.T) { Revocable: true, }) - assert.NoError(tt, err) - assert.NotEmpty(tt, createdCredResp) - assert.NotEmpty(tt, createdCredResp.CredentialJWT) + assert.NoError(t, err) + assert.NotEmpty(t, createdCredResp) + assert.NotEmpty(t, createdCredResp.CredentialJWT) credStatusMap, ok := createdCredResp.Credential.CredentialStatus.(map[string]any) - assert.True(tt, ok) + assert.True(t, ok) - assert.Contains(tt, credStatusMap["id"], fmt.Sprintf("%s/status", createdCredResp.Credential.ID)) - assert.Contains(tt, credStatusMap["statusListCredential"], "v1/credentials/status") - assert.NotEmpty(tt, credStatusMap["statusListIndex"]) + assert.Contains(t, credStatusMap["id"], fmt.Sprintf("%s/status", createdCredResp.Credential.ID)) + assert.Contains(t, credStatusMap["statusListCredential"], "v1/credentials/status") + assert.NotEmpty(t, credStatusMap["statusListIndex"]) createdCredRespTwo, err := credService.CreateCredential(context.Background(), credential.CreateCredentialRequest{ Issuer: issuer, @@ -442,24 +442,24 @@ func TestCredentialRouter(t *testing.T) { Revocable: true, }) - assert.NoError(tt, err) - assert.NotEmpty(tt, createdCredRespTwo) - assert.NotEmpty(tt, createdCredRespTwo.CredentialJWT) + assert.NoError(t, err) + assert.NotEmpty(t, createdCredRespTwo) + assert.NotEmpty(t, createdCredRespTwo.CredentialJWT) credStatusMapTwo, ok := createdCredRespTwo.Credential.CredentialStatus.(map[string]any) - assert.True(tt, ok) + assert.True(t, ok) - assert.Contains(tt, credStatusMapTwo["id"], fmt.Sprintf("%s/status", createdCredRespTwo.Credential.ID)) - assert.Contains(tt, credStatusMapTwo["statusListCredential"], "v1/credentials/status") - assert.NotEmpty(tt, credStatusMapTwo["statusListIndex"]) + assert.Contains(t, credStatusMapTwo["id"], fmt.Sprintf("%s/status", createdCredRespTwo.Credential.ID)) + assert.Contains(t, credStatusMapTwo["statusListCredential"], "v1/credentials/status") + assert.NotEmpty(t, credStatusMapTwo["statusListIndex"]) // Cred with same pair share the same statusListCredential - assert.Equal(tt, credStatusMapTwo["statusListCredential"], credStatusMap["statusListCredential"]) + assert.Equal(t, credStatusMapTwo["statusListCredential"], credStatusMap["statusListCredential"]) // create schema createdSchema, err := schemaService.CreateSchema(context.Background(), schema.CreateSchemaRequest{Issuer: issuerDID.DID.ID, Name: "simple schema", Schema: getEmailSchema()}) - assert.NoError(tt, err) - assert.NotEmpty(tt, createdSchema) + assert.NoError(t, err) + assert.NotEmpty(t, createdSchema) createdCredRespThree, err := credService.CreateCredential(context.Background(), credential.CreateCredentialRequest{ Issuer: issuer, @@ -473,45 +473,45 @@ func TestCredentialRouter(t *testing.T) { Revocable: true, }) - assert.NoError(tt, err) - assert.NotEmpty(tt, createdCredRespThree) - assert.NotEmpty(tt, createdCredRespThree.CredentialJWT) + assert.NoError(t, err) + assert.NotEmpty(t, createdCredRespThree) + assert.NotEmpty(t, createdCredRespThree.CredentialJWT) credStatusMapThree, ok := createdCredRespThree.Credential.CredentialStatus.(map[string]any) - assert.True(tt, ok) + assert.True(t, ok) - assert.Contains(tt, credStatusMapThree["id"], fmt.Sprintf("%s/status", createdCredRespThree.Credential.ID)) - assert.Contains(tt, credStatusMapThree["statusListCredential"], "v1/credentials/status") - assert.NotEmpty(tt, credStatusMapThree["statusListIndex"]) + assert.Contains(t, credStatusMapThree["id"], fmt.Sprintf("%s/status", createdCredRespThree.Credential.ID)) + assert.Contains(t, credStatusMapThree["statusListCredential"], "v1/credentials/status") + assert.NotEmpty(t, credStatusMapThree["statusListIndex"]) // Cred with different pair have different statusListCredential - assert.NotEqual(tt, credStatusMapThree["statusListCredential"], credStatusMap["statusListCredential"]) + assert.NotEqual(t, credStatusMapThree["statusListCredential"], credStatusMap["statusListCredential"]) }) - t.Run("Credential Status List Test Update Revoked Status", func(tt *testing.T) { - s := test.ServiceStorage(tt) - assert.NotEmpty(tt, s) + t.Run("Credential Status List Test Update Revoked Status", func(t *testing.T) { + s := test.ServiceStorage(t) + assert.NotEmpty(t, s) serviceConfig := config.CredentialServiceConfig{BatchCreateMaxItems: 100} - keyStoreService := testKeyStoreService(tt, s) - didService := testDIDService(tt, s, keyStoreService) - schemaService := testSchemaService(tt, s, keyStoreService, didService) + keyStoreService := testKeyStoreService(t, s) + didService := testDIDService(t, s, keyStoreService) + schemaService := testSchemaService(t, s, keyStoreService, didService) credService, err := credential.NewCredentialService(serviceConfig, s, keyStoreService, didService.GetResolver(), schemaService) - assert.NoError(tt, err) - assert.NotEmpty(tt, credService) + assert.NoError(t, err) + assert.NotEmpty(t, credService) // check type and status - assert.Equal(tt, framework.Credential, credService.Type()) - assert.Equal(tt, framework.StatusReady, credService.Status().Status) + assert.Equal(t, framework.Credential, credService.Type()) + assert.Equal(t, framework.StatusReady, credService.Status().Status) // create a did issuerDID, err := didService.CreateDIDByMethod(context.Background(), did.CreateDIDRequest{Method: didsdk.KeyMethod, KeyType: crypto.Ed25519}) - assert.NoError(tt, err) - assert.NotEmpty(tt, issuerDID) + assert.NoError(t, err) + assert.NotEmpty(t, issuerDID) // create a schema createdSchema, err := schemaService.CreateSchema(context.Background(), schema.CreateSchemaRequest{Issuer: issuerDID.DID.ID, Name: "simple schema", Schema: getEmailSchema()}) - assert.NoError(tt, err) - assert.NotEmpty(tt, createdSchema) + assert.NoError(t, err) + assert.NotEmpty(t, createdSchema) issuer := issuerDID.DID.ID subject := "did:test:345" @@ -526,10 +526,10 @@ func TestCredentialRouter(t *testing.T) { }, Expiry: time.Now().Add(24 * time.Hour).Format(time.RFC3339), }) - assert.NoError(tt, err) + assert.NoError(t, err) _, err = credService.UpdateCredentialStatus(context.Background(), credential.UpdateCredentialStatusRequest{ID: nonRevokableCred.ID, Revoked: true}) - assert.ErrorContains(tt, err, "has no credentialStatus field") + assert.ErrorContains(t, err, "has no credentialStatus field") createdCred, err := credService.CreateCredential(context.Background(), credential.CreateCredentialRequest{ Issuer: issuer, @@ -543,95 +543,95 @@ func TestCredentialRouter(t *testing.T) { Revocable: true, }) - assert.NoError(tt, err) - assert.NotEmpty(tt, createdCred) - assert.NotEmpty(tt, createdCred.CredentialJWT) + assert.NoError(t, err) + assert.NotEmpty(t, createdCred) + assert.NotEmpty(t, createdCred.CredentialJWT) statusBytes, err := json.Marshal(createdCred.Credential.CredentialStatus) - assert.NoError(tt, err) + assert.NoError(t, err) var statusEntry status.StatusList2021Entry err = json.Unmarshal(statusBytes, &statusEntry) - assert.NoError(tt, err) + assert.NoError(t, err) - assert.Contains(tt, statusEntry.ID, fmt.Sprintf("%s/status", createdCred.Credential.ID)) - assert.Contains(tt, statusEntry.StatusListCredential, "https://ssi-service.com/v1/credentials/status") - assert.NotEmpty(tt, statusEntry.StatusListIndex) + assert.Contains(t, statusEntry.ID, fmt.Sprintf("%s/status", createdCred.Credential.ID)) + assert.Contains(t, statusEntry.StatusListCredential, "https://ssi-service.com/v1/credentials/status") + assert.NotEmpty(t, statusEntry.StatusListIndex) credStatus, err := credService.GetCredentialStatus(context.Background(), credential.GetCredentialStatusRequest{ID: createdCred.ID}) - assert.NoError(tt, err) - assert.Equal(tt, credStatus.Revoked, false) + assert.NoError(t, err) + assert.Equal(t, credStatus.Revoked, false) credStatusListStr := statusEntry.StatusListCredential _, credStatusListID, ok := strings.Cut(credStatusListStr, "/v1/credentials/status/") - assert.True(tt, ok) + assert.True(t, ok) credStatusList, err := credService.GetCredentialStatusList(context.Background(), credential.GetCredentialStatusListRequest{ID: idFromURI(credStatusListID)}) - assert.NoError(tt, err) - assert.Equal(tt, credStatusList.Credential.ID, statusEntry.StatusListCredential) + assert.NoError(t, err) + assert.Equal(t, credStatusList.Credential.ID, statusEntry.StatusListCredential) credentialSubject := credStatusList.Container.Credential.CredentialSubject - assert.NotEmpty(tt, credentialSubject) + assert.NotEmpty(t, credentialSubject) encodedList := credentialSubject["encodedList"] - assert.NotEmpty(tt, encodedList) + assert.NotEmpty(t, encodedList) // Validate the StatusListIndex is not flipped in the credStatusList valid, err := status.ValidateCredentialInStatusList(*createdCred.Credential, *credStatusList.Credential) - assert.NoError(tt, err) - assert.False(tt, valid) + assert.NoError(t, err) + assert.False(t, valid) updatedStatus, err := credService.UpdateCredentialStatus(context.Background(), credential.UpdateCredentialStatusRequest{ID: createdCred.ID, Revoked: true}) - assert.NoError(tt, err) - assert.Equal(tt, updatedStatus.Revoked, true) + assert.NoError(t, err) + assert.Equal(t, updatedStatus.Revoked, true) updatedCred, err := credService.GetCredential(context.Background(), credential.GetCredentialRequest{ID: createdCred.ID}) - assert.NoError(tt, err) - assert.Equal(tt, updatedCred.Revoked, true) + assert.NoError(t, err) + assert.Equal(t, updatedCred.Revoked, true) credStatusListAfterRevoke, err := credService.GetCredentialStatusList(context.Background(), credential.GetCredentialStatusListRequest{ID: credStatusListID}) - assert.NoError(tt, err) - assert.Equal(tt, credStatusListAfterRevoke.Credential.ID, statusEntry.StatusListCredential) + assert.NoError(t, err) + assert.Equal(t, credStatusListAfterRevoke.Credential.ID, statusEntry.StatusListCredential) // Validate the StatusListIndex in flipped in the credStatusList valid, err = status.ValidateCredentialInStatusList(*createdCred.Credential, *credStatusListAfterRevoke.Credential) - assert.NoError(tt, err) - assert.True(tt, valid) + assert.NoError(t, err) + assert.True(t, valid) credentialSubjectAfterRevoke := credStatusListAfterRevoke.Container.Credential.CredentialSubject - assert.NotEmpty(tt, credentialSubjectAfterRevoke) + assert.NotEmpty(t, credentialSubjectAfterRevoke) encodedListAfterRevoke := credentialSubjectAfterRevoke["encodedList"] - assert.NotEmpty(tt, encodedListAfterRevoke) + assert.NotEmpty(t, encodedListAfterRevoke) - assert.NotEqualValues(tt, encodedListAfterRevoke, encodedList) + assert.NotEqualValues(t, encodedListAfterRevoke, encodedList) }) - t.Run("Credential Status List Test Update Suspended Status", func(tt *testing.T) { - s := test.ServiceStorage(tt) - assert.NotEmpty(tt, s) + t.Run("Credential Status List Test Update Suspended Status", func(t *testing.T) { + s := test.ServiceStorage(t) + assert.NotEmpty(t, s) serviceConfig := config.CredentialServiceConfig{BatchCreateMaxItems: 100} - keyStoreService := testKeyStoreService(tt, s) - didService := testDIDService(tt, s, keyStoreService) - schemaService := testSchemaService(tt, s, keyStoreService, didService) + keyStoreService := testKeyStoreService(t, s) + didService := testDIDService(t, s, keyStoreService) + schemaService := testSchemaService(t, s, keyStoreService, didService) credService, err := credential.NewCredentialService(serviceConfig, s, keyStoreService, didService.GetResolver(), schemaService) - assert.NoError(tt, err) - assert.NotEmpty(tt, credService) + assert.NoError(t, err) + assert.NotEmpty(t, credService) // check type and status - assert.Equal(tt, framework.Credential, credService.Type()) - assert.Equal(tt, framework.StatusReady, credService.Status().Status) + assert.Equal(t, framework.Credential, credService.Type()) + assert.Equal(t, framework.StatusReady, credService.Status().Status) // create a did issuerDID, err := didService.CreateDIDByMethod(context.Background(), did.CreateDIDRequest{Method: didsdk.KeyMethod, KeyType: crypto.Ed25519}) - assert.NoError(tt, err) - assert.NotEmpty(tt, issuerDID) + assert.NoError(t, err) + assert.NotEmpty(t, issuerDID) // create a schema createdSchema, err := schemaService.CreateSchema(context.Background(), schema.CreateSchemaRequest{Issuer: issuerDID.DID.ID, Name: "simple schema", Schema: getEmailSchema()}) - assert.NoError(tt, err) - assert.NotEmpty(tt, createdSchema) + assert.NoError(t, err) + assert.NotEmpty(t, createdSchema) issuer := issuerDID.DID.ID subject := "did:test:345" @@ -646,10 +646,10 @@ func TestCredentialRouter(t *testing.T) { }, Expiry: time.Now().Add(24 * time.Hour).Format(time.RFC3339), }) - assert.NoError(tt, err) + assert.NoError(t, err) _, err = credService.UpdateCredentialStatus(context.Background(), credential.UpdateCredentialStatusRequest{ID: nonSuspendableCred.ID, Suspended: true}) - assert.ErrorContains(tt, err, "has no credentialStatus field") + assert.ErrorContains(t, err, "has no credentialStatus field") createdCred, err := credService.CreateCredential(context.Background(), credential.CreateCredentialRequest{ Issuer: issuer, @@ -663,95 +663,95 @@ func TestCredentialRouter(t *testing.T) { Suspendable: true, }) - assert.NoError(tt, err) - assert.NotEmpty(tt, createdCred) - assert.NotEmpty(tt, createdCred.CredentialJWT) + assert.NoError(t, err) + assert.NotEmpty(t, createdCred) + assert.NotEmpty(t, createdCred.CredentialJWT) statusBytes, err := json.Marshal(createdCred.Credential.CredentialStatus) - assert.NoError(tt, err) + assert.NoError(t, err) var statusEntry status.StatusList2021Entry err = json.Unmarshal(statusBytes, &statusEntry) - assert.NoError(tt, err) + assert.NoError(t, err) - assert.Contains(tt, statusEntry.ID, fmt.Sprintf("%s/status", createdCred.Credential.ID)) - assert.Contains(tt, statusEntry.StatusListCredential, "https://ssi-service.com/v1/credentials/status") - assert.NotEmpty(tt, statusEntry.StatusListIndex) + assert.Contains(t, statusEntry.ID, fmt.Sprintf("%s/status", createdCred.Credential.ID)) + assert.Contains(t, statusEntry.StatusListCredential, "https://ssi-service.com/v1/credentials/status") + assert.NotEmpty(t, statusEntry.StatusListIndex) credStatus, err := credService.GetCredentialStatus(context.Background(), credential.GetCredentialStatusRequest{ID: createdCred.ID}) - assert.NoError(tt, err) - assert.Equal(tt, credStatus.Suspended, false) + assert.NoError(t, err) + assert.Equal(t, credStatus.Suspended, false) credStatusListStr := statusEntry.StatusListCredential _, credStatusListID, ok := strings.Cut(credStatusListStr, "/v1/credentials/status/") - assert.True(tt, ok) + assert.True(t, ok) credStatusList, err := credService.GetCredentialStatusList(context.Background(), credential.GetCredentialStatusListRequest{ID: idFromURI(credStatusListID)}) - assert.NoError(tt, err) - assert.Equal(tt, credStatusList.Credential.ID, statusEntry.StatusListCredential) + assert.NoError(t, err) + assert.Equal(t, credStatusList.Credential.ID, statusEntry.StatusListCredential) credentialSubject := credStatusList.Container.Credential.CredentialSubject - assert.NotEmpty(tt, credentialSubject) + assert.NotEmpty(t, credentialSubject) encodedList := credentialSubject["encodedList"] - assert.NotEmpty(tt, encodedList) + assert.NotEmpty(t, encodedList) // Validate the StatusListIndex is not flipped in the credStatusList valid, err := status.ValidateCredentialInStatusList(*createdCred.Credential, *credStatusList.Credential) - assert.NoError(tt, err) - assert.False(tt, valid) + assert.NoError(t, err) + assert.False(t, valid) updatedStatus, err := credService.UpdateCredentialStatus(context.Background(), credential.UpdateCredentialStatusRequest{ID: createdCred.ID, Suspended: true}) - assert.NoError(tt, err) - assert.Equal(tt, updatedStatus.Suspended, true) + assert.NoError(t, err) + assert.Equal(t, updatedStatus.Suspended, true) updatedCred, err := credService.GetCredential(context.Background(), credential.GetCredentialRequest{ID: createdCred.ID}) - assert.NoError(tt, err) - assert.Equal(tt, updatedCred.Suspended, true) + assert.NoError(t, err) + assert.Equal(t, updatedCred.Suspended, true) credStatusListAfterRevoke, err := credService.GetCredentialStatusList(context.Background(), credential.GetCredentialStatusListRequest{ID: idFromURI(credStatusListID)}) - assert.NoError(tt, err) - assert.Equal(tt, credStatusListAfterRevoke.Credential.ID, statusEntry.StatusListCredential) + assert.NoError(t, err) + assert.Equal(t, credStatusListAfterRevoke.Credential.ID, statusEntry.StatusListCredential) // Validate the StatusListIndex in flipped in the credStatusList valid, err = status.ValidateCredentialInStatusList(*createdCred.Credential, *credStatusListAfterRevoke.Credential) - assert.NoError(tt, err) - assert.True(tt, valid) + assert.NoError(t, err) + assert.True(t, valid) credentialSubjectAfterRevoke := credStatusListAfterRevoke.Container.Credential.CredentialSubject - assert.NotEmpty(tt, credentialSubjectAfterRevoke) + assert.NotEmpty(t, credentialSubjectAfterRevoke) encodedListAfterRevoke := credentialSubjectAfterRevoke["encodedList"] - assert.NotEmpty(tt, encodedListAfterRevoke) + assert.NotEmpty(t, encodedListAfterRevoke) - assert.NotEqualValues(tt, encodedListAfterRevoke, encodedList) + assert.NotEqualValues(t, encodedListAfterRevoke, encodedList) }) - t.Run("Create Multiple Suspendable Credential Different IssuerDID SchemaID StatusPurpose Triples", func(tt *testing.T) { - s := test.ServiceStorage(tt) - assert.NotEmpty(tt, s) + t.Run("Create Multiple Suspendable Credential Different IssuerDID SchemaID StatusPurpose Triples", func(t *testing.T) { + s := test.ServiceStorage(t) + assert.NotEmpty(t, s) serviceConfig := config.CredentialServiceConfig{BatchCreateMaxItems: 100} - keyStoreService := testKeyStoreService(tt, s) - didService := testDIDService(tt, s, keyStoreService) - schemaService := testSchemaService(tt, s, keyStoreService, didService) + keyStoreService := testKeyStoreService(t, s) + didService := testDIDService(t, s, keyStoreService) + schemaService := testSchemaService(t, s, keyStoreService, didService) credService, err := credential.NewCredentialService(serviceConfig, s, keyStoreService, didService.GetResolver(), schemaService) - assert.NoError(tt, err) - assert.NotEmpty(tt, credService) + assert.NoError(t, err) + assert.NotEmpty(t, credService) // check type and status - assert.Equal(tt, framework.Credential, credService.Type()) - assert.Equal(tt, framework.StatusReady, credService.Status().Status) + assert.Equal(t, framework.Credential, credService.Type()) + assert.Equal(t, framework.StatusReady, credService.Status().Status) // create a did issuerDID, err := didService.CreateDIDByMethod(context.Background(), did.CreateDIDRequest{Method: didsdk.KeyMethod, KeyType: crypto.Ed25519}) - assert.NoError(tt, err) - assert.NotEmpty(tt, issuerDID) + assert.NoError(t, err) + assert.NotEmpty(t, issuerDID) // create a schema createdSchema, err := schemaService.CreateSchema(context.Background(), schema.CreateSchemaRequest{Issuer: issuerDID.DID.ID, Name: "simple schema", Schema: getEmailSchema()}) - assert.NoError(tt, err) - assert.NotEmpty(tt, createdSchema) + assert.NoError(t, err) + assert.NotEmpty(t, createdSchema) subject := "did:test:345" @@ -766,8 +766,8 @@ func TestCredentialRouter(t *testing.T) { Expiry: time.Now().Add(24 * time.Hour).Format(time.RFC3339), Revocable: true, }) - assert.NoError(tt, err) - assert.NotEmpty(tt, createdCred) + assert.NoError(t, err) + assert.NotEmpty(t, createdCred) createdCredSuspendable, err := credService.CreateCredential(context.Background(), credential.CreateCredentialRequest{ Issuer: issuerDID.DID.ID, @@ -780,40 +780,40 @@ func TestCredentialRouter(t *testing.T) { Expiry: time.Now().Add(24 * time.Hour).Format(time.RFC3339), Suspendable: true, }) - assert.NoError(tt, err) - assert.NotEmpty(tt, createdCredSuspendable) + assert.NoError(t, err) + assert.NotEmpty(t, createdCredSuspendable) revocationKey := storage.Join("is", issuerDID.DID.ID, "sc", createdSchema.ID, "sp", string(status.StatusRevocation)) slcExists, err := s.Exists(context.Background(), "status-list-credential", revocationKey) - assert.NoError(tt, err) - assert.True(tt, slcExists) + assert.NoError(t, err) + assert.True(t, slcExists) indexPoolExists, err := s.Exists(context.Background(), "status-list-index-pool", revocationKey) - assert.NoError(tt, err) - assert.True(tt, indexPoolExists) + assert.NoError(t, err) + assert.True(t, indexPoolExists) currentIndexExists, err := s.Exists(context.Background(), "status-list-current-index", revocationKey) - assert.NoError(tt, err) - assert.True(tt, currentIndexExists) + assert.NoError(t, err) + assert.True(t, currentIndexExists) suspensionKey := storage.Join("is", issuerDID.DID.ID, "sc", createdSchema.ID, "sp", string(status.StatusSuspension)) slcExists, err = s.Exists(context.Background(), "status-list-credential", suspensionKey) - assert.NoError(tt, err) - assert.True(tt, slcExists) + assert.NoError(t, err) + assert.True(t, slcExists) indexPoolExists, err = s.Exists(context.Background(), "status-list-index-pool", suspensionKey) - assert.NoError(tt, err) - assert.True(tt, indexPoolExists) + assert.NoError(t, err) + assert.True(t, indexPoolExists) currentIndexExists, err = s.Exists(context.Background(), "status-list-current-index", suspensionKey) - assert.NoError(tt, err) - assert.True(tt, currentIndexExists) + assert.NoError(t, err) + assert.True(t, currentIndexExists) }) - t.Run("Create Suspendable Credential", func(tt *testing.T) { - issuer, verificationMethodID, schemaID, credService := createCredServicePrereqs(tt, test.ServiceStorage(tt)) + t.Run("Create Suspendable Credential", func(t *testing.T) { + issuer, verificationMethodID, schemaID, credService := createCredServicePrereqs(t, test.ServiceStorage(t)) subject := "did:test:345" createdCred, err := credService.CreateCredential(context.Background(), credential.CreateCredentialRequest{ @@ -828,48 +828,48 @@ func TestCredentialRouter(t *testing.T) { Suspendable: true, }) - assert.NoError(tt, err) - assert.NotEmpty(tt, createdCred) - assert.NotEmpty(tt, createdCred.CredentialJWT) + assert.NoError(t, err) + assert.NotEmpty(t, createdCred) + assert.NotEmpty(t, createdCred.CredentialJWT) statusBytes, err := json.Marshal(createdCred.Credential.CredentialStatus) - assert.NoError(tt, err) + assert.NoError(t, err) var statusEntry status.StatusList2021Entry err = json.Unmarshal(statusBytes, &statusEntry) - assert.NoError(tt, err) + assert.NoError(t, err) - assert.Contains(tt, statusEntry.ID, fmt.Sprintf("%s/status", createdCred.Credential.ID)) - assert.Contains(tt, statusEntry.StatusListCredential, "https://ssi-service.com/v1/credentials/status") - assert.NotEmpty(tt, statusEntry.StatusListIndex) + assert.Contains(t, statusEntry.ID, fmt.Sprintf("%s/status", createdCred.Credential.ID)) + assert.Contains(t, statusEntry.StatusListCredential, "https://ssi-service.com/v1/credentials/status") + assert.NotEmpty(t, statusEntry.StatusListIndex) credStatus, err := credService.GetCredentialStatus(context.Background(), credential.GetCredentialStatusRequest{ID: createdCred.ID}) - assert.NoError(tt, err) - assert.Equal(tt, credStatus.Revoked, false) - assert.Equal(tt, credStatus.Suspended, false) + assert.NoError(t, err) + assert.Equal(t, credStatus.Revoked, false) + assert.Equal(t, credStatus.Suspended, false) credStatusListStr := statusEntry.StatusListCredential _, credStatusListID, ok := strings.Cut(credStatusListStr, "/v1/credentials/status/") - assert.True(tt, ok) + assert.True(t, ok) credStatusList, err := credService.GetCredentialStatusList(context.Background(), credential.GetCredentialStatusListRequest{ID: idFromURI(credStatusListID)}) - assert.NoError(tt, err) - assert.Equal(tt, credStatusList.Credential.ID, statusEntry.StatusListCredential) + assert.NoError(t, err) + assert.Equal(t, credStatusList.Credential.ID, statusEntry.StatusListCredential) credentialSubject := credStatusList.Container.Credential.CredentialSubject - assert.NotEmpty(tt, credentialSubject) + assert.NotEmpty(t, credentialSubject) encodedList := credentialSubject["encodedList"] - assert.NotEmpty(tt, encodedList) + assert.NotEmpty(t, encodedList) // Validate the StatusListIndex is not flipped in the credStatusList valid, err := status.ValidateCredentialInStatusList(*createdCred.Credential, *credStatusList.Credential) - assert.NoError(tt, err) - assert.False(tt, valid) + assert.NoError(t, err) + assert.False(t, valid) }) - t.Run("Update Suspendable Credential To Suspended", func(tt *testing.T) { - issuer, verificationMethodID, schemaID, credService := createCredServicePrereqs(tt, test.ServiceStorage(tt)) + t.Run("Update Suspendable Credential To Suspended", func(t *testing.T) { + issuer, verificationMethodID, schemaID, credService := createCredServicePrereqs(t, test.ServiceStorage(t)) subject := "did:test:345" createdCred, err := credService.CreateCredential(context.Background(), credential.CreateCredentialRequest{ @@ -884,70 +884,70 @@ func TestCredentialRouter(t *testing.T) { Suspendable: true, }) - assert.NoError(tt, err) - assert.NotEmpty(tt, createdCred) - assert.NotEmpty(tt, createdCred.CredentialJWT) + assert.NoError(t, err) + assert.NotEmpty(t, createdCred) + assert.NotEmpty(t, createdCred.CredentialJWT) statusBytes, err := json.Marshal(createdCred.Credential.CredentialStatus) - assert.NoError(tt, err) + assert.NoError(t, err) var statusEntry status.StatusList2021Entry err = json.Unmarshal(statusBytes, &statusEntry) - assert.NoError(tt, err) + assert.NoError(t, err) - assert.Contains(tt, statusEntry.ID, fmt.Sprintf("%s/status", createdCred.Credential.ID)) - assert.Contains(tt, statusEntry.StatusListCredential, "https://ssi-service.com/v1/credentials/status") - assert.NotEmpty(tt, statusEntry.StatusListIndex) + assert.Contains(t, statusEntry.ID, fmt.Sprintf("%s/status", createdCred.Credential.ID)) + assert.Contains(t, statusEntry.StatusListCredential, "https://ssi-service.com/v1/credentials/status") + assert.NotEmpty(t, statusEntry.StatusListIndex) credStatus, err := credService.GetCredentialStatus(context.Background(), credential.GetCredentialStatusRequest{ID: createdCred.ID}) - assert.NoError(tt, err) - assert.Equal(tt, credStatus.Revoked, false) - assert.Equal(tt, credStatus.Suspended, false) + assert.NoError(t, err) + assert.Equal(t, credStatus.Revoked, false) + assert.Equal(t, credStatus.Suspended, false) credStatusListStr := statusEntry.StatusListCredential _, credStatusListID, ok := strings.Cut(credStatusListStr, "/v1/credentials/status/") - assert.True(tt, ok) + assert.True(t, ok) credStatusList, err := credService.GetCredentialStatusList(context.Background(), credential.GetCredentialStatusListRequest{ID: idFromURI(credStatusListID)}) - assert.NoError(tt, err) - assert.Equal(tt, credStatusList.Credential.ID, statusEntry.StatusListCredential) + assert.NoError(t, err) + assert.Equal(t, credStatusList.Credential.ID, statusEntry.StatusListCredential) credentialSubject := credStatusList.Container.Credential.CredentialSubject - assert.NotEmpty(tt, credentialSubject) + assert.NotEmpty(t, credentialSubject) encodedList := credentialSubject["encodedList"] - assert.NotEmpty(tt, encodedList) + assert.NotEmpty(t, encodedList) // Validate the StatusListIndex is not flipped in the credStatusList valid, err := status.ValidateCredentialInStatusList(*createdCred.Credential, *credStatusList.Credential) - assert.NoError(tt, err) - assert.False(tt, valid) + assert.NoError(t, err) + assert.False(t, valid) updatedStatus, err := credService.UpdateCredentialStatus(context.Background(), credential.UpdateCredentialStatusRequest{ID: createdCred.ID, Suspended: true}) - assert.NoError(tt, err) - assert.Equal(tt, updatedStatus.Suspended, true) - assert.Equal(tt, updatedStatus.Revoked, false) + assert.NoError(t, err) + assert.Equal(t, updatedStatus.Suspended, true) + assert.Equal(t, updatedStatus.Revoked, false) credStatusListAfterRevoke, err := credService.GetCredentialStatusList(context.Background(), credential.GetCredentialStatusListRequest{ID: idFromURI(credStatusListID)}) - assert.NoError(tt, err) - assert.Equal(tt, credStatusListAfterRevoke.Credential.ID, statusEntry.StatusListCredential) + assert.NoError(t, err) + assert.Equal(t, credStatusListAfterRevoke.Credential.ID, statusEntry.StatusListCredential) // Validate the StatusListIndex in flipped in the credStatusList valid, err = status.ValidateCredentialInStatusList(*createdCred.Credential, *credStatusListAfterRevoke.Credential) - assert.NoError(tt, err) - assert.True(tt, valid) + assert.NoError(t, err) + assert.True(t, valid) credentialSubjectAfterRevoke := credStatusListAfterRevoke.Container.Credential.CredentialSubject - assert.NotEmpty(tt, credentialSubjectAfterRevoke) + assert.NotEmpty(t, credentialSubjectAfterRevoke) encodedListAfterSuspended := credentialSubjectAfterRevoke["encodedList"] - assert.NotEmpty(tt, encodedListAfterSuspended) + assert.NotEmpty(t, encodedListAfterSuspended) - assert.NotEqualValues(tt, encodedListAfterSuspended, encodedList) + assert.NotEqualValues(t, encodedListAfterSuspended, encodedList) }) - t.Run("Update Suspendable Credential To Suspended then Unsuspended", func(tt *testing.T) { - issuer, verificationMethodID, schemaID, credService := createCredServicePrereqs(tt, test.ServiceStorage(tt)) + t.Run("Update Suspendable Credential To Suspended then Unsuspended", func(t *testing.T) { + issuer, verificationMethodID, schemaID, credService := createCredServicePrereqs(t, test.ServiceStorage(t)) subject := "did:test:345" createdCred, err := credService.CreateCredential(context.Background(), credential.CreateCredentialRequest{ @@ -962,75 +962,75 @@ func TestCredentialRouter(t *testing.T) { Suspendable: true, }) - assert.NoError(tt, err) - assert.NotEmpty(tt, createdCred) - assert.NotEmpty(tt, createdCred.CredentialJWT) + assert.NoError(t, err) + assert.NotEmpty(t, createdCred) + assert.NotEmpty(t, createdCred.CredentialJWT) statusBytes, err := json.Marshal(createdCred.Credential.CredentialStatus) - assert.NoError(tt, err) + assert.NoError(t, err) var statusEntry status.StatusList2021Entry err = json.Unmarshal(statusBytes, &statusEntry) - assert.NoError(tt, err) + assert.NoError(t, err) - assert.Contains(tt, statusEntry.ID, fmt.Sprintf("%s/status", createdCred.Credential.ID)) - assert.Contains(tt, statusEntry.StatusListCredential, "https://ssi-service.com/v1/credentials/status") - assert.NotEmpty(tt, statusEntry.StatusListIndex) + assert.Contains(t, statusEntry.ID, fmt.Sprintf("%s/status", createdCred.Credential.ID)) + assert.Contains(t, statusEntry.StatusListCredential, "https://ssi-service.com/v1/credentials/status") + assert.NotEmpty(t, statusEntry.StatusListIndex) credStatus, err := credService.GetCredentialStatus(context.Background(), credential.GetCredentialStatusRequest{ID: createdCred.ID}) - assert.NoError(tt, err) - assert.Equal(tt, credStatus.Revoked, false) - assert.Equal(tt, credStatus.Suspended, false) + assert.NoError(t, err) + assert.Equal(t, credStatus.Revoked, false) + assert.Equal(t, credStatus.Suspended, false) credStatusListStr := statusEntry.StatusListCredential _, credStatusListID, ok := strings.Cut(credStatusListStr, "/v1/credentials/status/") - assert.True(tt, ok) + assert.True(t, ok) credStatusList, err := credService.GetCredentialStatusList(context.Background(), credential.GetCredentialStatusListRequest{ID: idFromURI(credStatusListID)}) - assert.NoError(tt, err) - assert.Equal(tt, credStatusList.Credential.ID, statusEntry.StatusListCredential) + assert.NoError(t, err) + assert.Equal(t, credStatusList.Credential.ID, statusEntry.StatusListCredential) credentialSubject := credStatusList.Container.Credential.CredentialSubject - assert.NotEmpty(tt, credentialSubject) + assert.NotEmpty(t, credentialSubject) encodedList := credentialSubject["encodedList"] - assert.NotEmpty(tt, encodedList) + assert.NotEmpty(t, encodedList) // Validate the StatusListIndex is not flipped in the credStatusList valid, err := status.ValidateCredentialInStatusList(*createdCred.Credential, *credStatusList.Credential) - assert.NoError(tt, err) - assert.False(tt, valid) + assert.NoError(t, err) + assert.False(t, valid) updatedStatus, err := credService.UpdateCredentialStatus(context.Background(), credential.UpdateCredentialStatusRequest{ID: createdCred.ID, Suspended: true}) - assert.NoError(tt, err) - assert.Equal(tt, updatedStatus.Suspended, true) - assert.Equal(tt, updatedStatus.Revoked, false) + assert.NoError(t, err) + assert.Equal(t, updatedStatus.Suspended, true) + assert.Equal(t, updatedStatus.Revoked, false) credStatusListAfterRevoke, err := credService.GetCredentialStatusList(context.Background(), credential.GetCredentialStatusListRequest{ID: idFromURI(credStatusListID)}) - assert.NoError(tt, err) - assert.Equal(tt, credStatusListAfterRevoke.Credential.ID, statusEntry.StatusListCredential) + assert.NoError(t, err) + assert.Equal(t, credStatusListAfterRevoke.Credential.ID, statusEntry.StatusListCredential) // Validate the StatusListIndex in flipped in the credStatusList valid, err = status.ValidateCredentialInStatusList(*createdCred.Credential, *credStatusListAfterRevoke.Credential) - assert.NoError(tt, err) - assert.True(tt, valid) + assert.NoError(t, err) + assert.True(t, valid) credentialSubjectAfterRevoke := credStatusListAfterRevoke.Container.Credential.CredentialSubject - assert.NotEmpty(tt, credentialSubjectAfterRevoke) + assert.NotEmpty(t, credentialSubjectAfterRevoke) encodedListAfterSuspended := credentialSubjectAfterRevoke["encodedList"] - assert.NotEmpty(tt, encodedListAfterSuspended) + assert.NotEmpty(t, encodedListAfterSuspended) - assert.NotEqualValues(tt, encodedListAfterSuspended, encodedList) + assert.NotEqualValues(t, encodedListAfterSuspended, encodedList) updatedStatus, err = credService.UpdateCredentialStatus(context.Background(), credential.UpdateCredentialStatusRequest{ID: createdCred.ID, Suspended: false}) - assert.NoError(tt, err) - assert.Equal(tt, updatedStatus.Suspended, false) - assert.Equal(tt, updatedStatus.Revoked, false) + assert.NoError(t, err) + assert.Equal(t, updatedStatus.Suspended, false) + assert.Equal(t, updatedStatus.Revoked, false) }) - t.Run("Create Suspendable and Revocable Credential Should Be Error", func(tt *testing.T) { - issuer, verificationMethodID, schemaID, credService := createCredServicePrereqs(tt, test.ServiceStorage(tt)) + t.Run("Create Suspendable and Revocable Credential Should Be Error", func(t *testing.T) { + issuer, verificationMethodID, schemaID, credService := createCredServicePrereqs(t, test.ServiceStorage(t)) subject := "did:test:345" createdCred, err := credService.CreateCredential(context.Background(), credential.CreateCredentialRequest{ @@ -1046,13 +1046,13 @@ func TestCredentialRouter(t *testing.T) { Suspendable: true, }) - assert.Error(tt, err) - assert.ErrorContains(tt, err, "credential may have at most one status") - assert.Empty(tt, createdCred) + assert.Error(t, err) + assert.ErrorContains(t, err, "credential may have at most one status") + assert.Empty(t, createdCred) }) - t.Run("Update Suspendable and Revocable Credential Should Be Error", func(tt *testing.T) { - issuer, verificationMethodID, schemaID, credService := createCredServicePrereqs(tt, test.ServiceStorage(tt)) + t.Run("Update Suspendable and Revocable Credential Should Be Error", func(t *testing.T) { + issuer, verificationMethodID, schemaID, credService := createCredServicePrereqs(t, test.ServiceStorage(t)) subject := "did:test:345" createdCred, err := credService.CreateCredential(context.Background(), credential.CreateCredentialRequest{ @@ -1067,17 +1067,17 @@ func TestCredentialRouter(t *testing.T) { Suspendable: true, }) - assert.NoError(tt, err) - assert.NotEmpty(tt, createdCred) + assert.NoError(t, err) + assert.NotEmpty(t, createdCred) updatedStatus, err := credService.UpdateCredentialStatus(context.Background(), credential.UpdateCredentialStatusRequest{ID: createdCred.ID, Revoked: true, Suspended: true}) - assert.Nil(tt, updatedStatus) - assert.Error(tt, err) - assert.ErrorContains(tt, err, "cannot update both suspended and revoked status") + assert.Nil(t, updatedStatus) + assert.Error(t, err) + assert.ErrorContains(t, err, "cannot update both suspended and revoked status") }) - t.Run("Update Suspended On Revoked Credential Should Be Error", func(tt *testing.T) { - issuer, verificationMethodID, schemaID, credService := createCredServicePrereqs(tt, test.ServiceStorage(tt)) + t.Run("Update Suspended On Revoked Credential Should Be Error", func(t *testing.T) { + issuer, verificationMethodID, schemaID, credService := createCredServicePrereqs(t, test.ServiceStorage(t)) subject := "did:test:345" createdCred, err := credService.CreateCredential(context.Background(), credential.CreateCredentialRequest{ @@ -1092,17 +1092,17 @@ func TestCredentialRouter(t *testing.T) { Revocable: true, }) - assert.NoError(tt, err) - assert.NotEmpty(tt, createdCred) + assert.NoError(t, err) + assert.NotEmpty(t, createdCred) updatedStatus, err := credService.UpdateCredentialStatus(context.Background(), credential.UpdateCredentialStatusRequest{ID: createdCred.ID, Suspended: true}) - assert.Nil(tt, updatedStatus) - assert.Error(tt, err) - assert.ErrorContains(tt, err, "has a different status purpose value than the status credential") + assert.Nil(t, updatedStatus) + assert.Error(t, err) + assert.ErrorContains(t, err, "has a different status purpose value than the status credential") }) - t.Run("Create Credential With Invalid Evidence", func(tt *testing.T) { - issuer, verificationMethodID, schemaID, credService := createCredServicePrereqs(tt, test.ServiceStorage(tt)) + t.Run("Create Credential With Invalid Evidence", func(t *testing.T) { + issuer, verificationMethodID, schemaID, credService := createCredServicePrereqs(t, test.ServiceStorage(t)) subject := "did:test:345" _, err := credService.CreateCredential(context.Background(), credential.CreateCredentialRequest{ @@ -1117,11 +1117,11 @@ func TestCredentialRouter(t *testing.T) { Evidence: []any{"hi", 123, true}, }) - assert.ErrorContains(tt, err, "invalid evidence format") + assert.ErrorContains(t, err, "invalid evidence format") }) - t.Run("Create Credential With Invalid Evidence No Id", func(tt *testing.T) { - issuer, verificationMethodID, schemaID, credService := createCredServicePrereqs(tt, test.ServiceStorage(tt)) + t.Run("Create Credential With Invalid Evidence No Id", func(t *testing.T) { + issuer, verificationMethodID, schemaID, credService := createCredServicePrereqs(t, test.ServiceStorage(t)) subject := "did:test:345" evidenceMap := map[string]any{ @@ -1145,11 +1145,11 @@ func TestCredentialRouter(t *testing.T) { Evidence: []any{evidenceMap}, }) - assert.ErrorContains(tt, err, "missing required 'id' or 'type'") + assert.ErrorContains(t, err, "missing required 'id' or 'type'") }) - t.Run("Create Credential With Evidence", func(tt *testing.T) { - issuer, verificationMethodID, schemaID, credService := createCredServicePrereqs(tt, test.ServiceStorage(tt)) + t.Run("Create Credential With Evidence", func(t *testing.T) { + issuer, verificationMethodID, schemaID, credService := createCredServicePrereqs(t, test.ServiceStorage(t)) subject := "did:test:345" createdCred, err := credService.CreateCredential(context.Background(), credential.CreateCredentialRequest{ @@ -1164,11 +1164,11 @@ func TestCredentialRouter(t *testing.T) { Evidence: getEvidence(), }) - assert.NoError(tt, err) - assert.NotEmpty(tt, createdCred) - assert.NotEmpty(tt, createdCred.CredentialJWT) + assert.NoError(t, err) + assert.NotEmpty(t, createdCred) + assert.NotEmpty(t, createdCred.CredentialJWT) - assert.ElementsMatch(tt, createdCred.Credential.Evidence, getEvidence()) + assert.ElementsMatch(t, createdCred.Credential.Evidence, getEvidence()) }) }) } @@ -1178,30 +1178,30 @@ func idFromURI(cred string) string { return cred[len(cred)-36:] } -func createCredServicePrereqs(tt *testing.T, s storage.ServiceStorage) (issuer, verificationMethodID, schemaID string, credSvc credential.Service) { - require.NotEmpty(tt, s) +func createCredServicePrereqs(t *testing.T, s storage.ServiceStorage) (issuer, verificationMethodID, schemaID string, credSvc credential.Service) { + require.NotEmpty(t, s) serviceConfig := config.CredentialServiceConfig{BatchCreateMaxItems: 100} - keyStoreService := testKeyStoreService(tt, s) - didService := testDIDService(tt, s, keyStoreService) - schemaService := testSchemaService(tt, s, keyStoreService, didService) + keyStoreService := testKeyStoreService(t, s) + didService := testDIDService(t, s, keyStoreService) + schemaService := testSchemaService(t, s, keyStoreService, didService) credService, err := credential.NewCredentialService(serviceConfig, s, keyStoreService, didService.GetResolver(), schemaService) - require.NoError(tt, err) - require.NotEmpty(tt, credService) + require.NoError(t, err) + require.NotEmpty(t, credService) // check type and status - require.Equal(tt, framework.Credential, credService.Type()) - require.Equal(tt, framework.StatusReady, credService.Status().Status) + require.Equal(t, framework.Credential, credService.Type()) + require.Equal(t, framework.StatusReady, credService.Status().Status) // create a did issuerDID, err := didService.CreateDIDByMethod(context.Background(), did.CreateDIDRequest{Method: didsdk.KeyMethod, KeyType: crypto.Ed25519}) - require.NoError(tt, err) - require.NotEmpty(tt, issuerDID) + require.NoError(t, err) + require.NotEmpty(t, issuerDID) // create a schema createdSchema, err := schemaService.CreateSchema(context.Background(), schema.CreateSchemaRequest{Issuer: issuerDID.DID.ID, Name: "simple schema", Schema: getEmailSchema()}) - require.NoError(tt, err) - require.NotEmpty(tt, createdSchema) + require.NoError(t, err) + require.NotEmpty(t, createdSchema) return issuerDID.DID.ID, issuerDID.DID.VerificationMethod[0].ID, createdSchema.ID, *credService } diff --git a/pkg/server/router/did_test.go b/pkg/server/router/did_test.go index c1a6e1aa5..6956011fe 100644 --- a/pkg/server/router/did_test.go +++ b/pkg/server/router/did_test.go @@ -18,35 +18,35 @@ import ( ) func TestDIDRouter(t *testing.T) { - t.Run("Nil Service", func(tt *testing.T) { + t.Run("Nil Service", func(t *testing.T) { didRouter, err := NewDIDRouter(nil) - assert.Error(tt, err) - assert.Empty(tt, didRouter) - assert.Contains(tt, err.Error(), "service cannot be nil") + assert.Error(t, err) + assert.Empty(t, didRouter) + assert.Contains(t, err.Error(), "service cannot be nil") }) - t.Run("Bad Service", func(tt *testing.T) { + t.Run("Bad Service", func(t *testing.T) { didRouter, err := NewDIDRouter(&testService{}) - assert.Error(tt, err) - assert.Empty(tt, didRouter) - assert.Contains(tt, err.Error(), "could not create DID router with service type: test") + assert.Error(t, err) + assert.Empty(t, didRouter) + assert.Contains(t, err.Error(), "could not create DID router with service type: test") }) for _, test := range testutil.TestDatabases { t.Run(test.Name, func(t *testing.T) { // TODO: Fix pagesize issue on redis - https://github.com/TBD54566975/ssi-service/issues/538 if !strings.Contains(test.Name, "Redis") { - t.Run("List DIDs supports paging", func(tt *testing.T) { - db := test.ServiceStorage(tt) - assert.NotEmpty(tt, db) - keyStoreService := testKeyStoreService(tt, db) + t.Run("List DIDs supports paging", func(t *testing.T) { + db := test.ServiceStorage(t) + assert.NotEmpty(t, db) + keyStoreService := testKeyStoreService(t, db) methods := []string{didsdk.KeyMethod.String()} serviceConfig := config.DIDServiceConfig{Methods: methods, LocalResolutionMethods: methods} didService, err := did.NewDIDService(serviceConfig, db, keyStoreService, nil) - assert.NoError(tt, err) - assert.NotEmpty(tt, didService) - createDID(tt, didService) - createDID(tt, didService) + assert.NoError(t, err) + assert.NotEmpty(t, didService) + createDID(t, didService) + createDID(t, didService) one := 1 listDIDsResponse1, err := didService.ListDIDsByMethod(context.Background(), @@ -57,9 +57,9 @@ func TestDIDRouter(t *testing.T) { }, }) - assert.NoError(tt, err) - assert.Len(tt, listDIDsResponse1.DIDs, 1) - assert.NotEmpty(tt, listDIDsResponse1.NextPageToken) + assert.NoError(t, err) + assert.Len(t, listDIDsResponse1.DIDs, 1) + assert.NotEmpty(t, listDIDsResponse1.NextPageToken) listDIDsResponse2, err := didService.ListDIDsByMethod(context.Background(), did.ListDIDsRequest{ @@ -70,125 +70,125 @@ func TestDIDRouter(t *testing.T) { }, }) - assert.NoError(tt, err) - assert.Len(tt, listDIDsResponse2.DIDs, 1) - assert.Empty(tt, listDIDsResponse2.NextPageToken) + assert.NoError(t, err) + assert.Len(t, listDIDsResponse2.DIDs, 1) + assert.Empty(t, listDIDsResponse2.NextPageToken) }) } - t.Run("DID Service Test", func(tt *testing.T) { - db := test.ServiceStorage(tt) - assert.NotEmpty(tt, db) + t.Run("DID Service Test", func(t *testing.T) { + db := test.ServiceStorage(t) + assert.NotEmpty(t, db) - keyStoreService := testKeyStoreService(tt, db) + keyStoreService := testKeyStoreService(t, db) methods := []string{didsdk.KeyMethod.String()} serviceConfig := config.DIDServiceConfig{Methods: methods, LocalResolutionMethods: methods} didService, err := did.NewDIDService(serviceConfig, db, keyStoreService, nil) - assert.NoError(tt, err) - assert.NotEmpty(tt, didService) + assert.NoError(t, err) + assert.NotEmpty(t, didService) // check type and status - assert.Equal(tt, framework.DID, didService.Type()) - assert.Equal(tt, framework.StatusReady, didService.Status().Status) + assert.Equal(t, framework.DID, didService.Type()) + assert.Equal(t, framework.StatusReady, didService.Status().Status) // get unknown handler _, err = didService.GetDIDByMethod(context.Background(), did.GetDIDRequest{Method: "bad"}) - assert.Error(tt, err) - assert.Contains(tt, err.Error(), "could not get handler for method") + assert.Error(t, err) + assert.Contains(t, err.Error(), "could not get handler for method") supported := didService.GetSupportedMethods() - assert.NotEmpty(tt, supported) - assert.Len(tt, supported.Methods, 1) - assert.Equal(tt, didsdk.KeyMethod, supported.Methods[0]) + assert.NotEmpty(t, supported) + assert.Len(t, supported.Methods, 1) + assert.Equal(t, didsdk.KeyMethod, supported.Methods[0]) // bad key type _, err = didService.CreateDIDByMethod(context.Background(), did.CreateDIDRequest{Method: didsdk.KeyMethod, KeyType: "bad"}) - assert.Error(tt, err) - assert.Contains(tt, err.Error(), "unsupported did:key type: bad") + assert.Error(t, err) + assert.Contains(t, err.Error(), "unsupported did:key type: bad") // good key type createDIDResponse, err := didService.CreateDIDByMethod(context.Background(), did.CreateDIDRequest{Method: didsdk.KeyMethod, KeyType: crypto.Ed25519}) - assert.NoError(tt, err) - assert.NotEmpty(tt, createDIDResponse) + assert.NoError(t, err) + assert.NotEmpty(t, createDIDResponse) // check the DID is a did:key - assert.Contains(tt, createDIDResponse.DID.ID, "did:key") + assert.Contains(t, createDIDResponse.DID.ID, "did:key") // get it back getDIDResponse, err := didService.GetDIDByMethod(context.Background(), did.GetDIDRequest{Method: didsdk.KeyMethod, ID: createDIDResponse.DID.ID}) - assert.NoError(tt, err) - assert.NotEmpty(tt, getDIDResponse) + assert.NoError(t, err) + assert.NotEmpty(t, getDIDResponse) // make sure it's the same value - assert.Equal(tt, createDIDResponse.DID.ID, getDIDResponse.DID.ID) + assert.Equal(t, createDIDResponse.DID.ID, getDIDResponse.DID.ID) // create a second DID createDIDResponse2, err := didService.CreateDIDByMethod(context.Background(), did.CreateDIDRequest{Method: didsdk.KeyMethod, KeyType: crypto.Ed25519}) - assert.NoError(tt, err) - assert.NotEmpty(tt, createDIDResponse2) + assert.NoError(t, err) + assert.NotEmpty(t, createDIDResponse2) // get all DIDs back getDIDsResponse, err := didService.ListDIDsByMethod(context.Background(), did.ListDIDsRequest{Method: didsdk.KeyMethod}) - assert.NoError(tt, err) - assert.NotEmpty(tt, getDIDsResponse) - assert.Len(tt, getDIDsResponse.DIDs, 2) + assert.NoError(t, err) + assert.NotEmpty(t, getDIDsResponse) + assert.Len(t, getDIDsResponse.DIDs, 2) knownDIDs := map[string]bool{createDIDResponse.DID.ID: true, createDIDResponse2.DID.ID: true} for _, gotDID := range getDIDsResponse.DIDs { if _, ok := knownDIDs[gotDID.ID]; !ok { - tt.Error("got unknown DID") + t.Error("got unknown DID") } else { delete(knownDIDs, gotDID.ID) } } - assert.Len(tt, knownDIDs, 0) + assert.Len(t, knownDIDs, 0) // delete dids err = didService.SoftDeleteDIDByMethod(context.Background(), did.DeleteDIDRequest{Method: didsdk.KeyMethod, ID: createDIDResponse.DID.ID}) - assert.NoError(tt, err) + assert.NoError(t, err) err = didService.SoftDeleteDIDByMethod(context.Background(), did.DeleteDIDRequest{Method: didsdk.KeyMethod, ID: createDIDResponse2.DID.ID}) - assert.NoError(tt, err) + assert.NoError(t, err) // get all DIDs back getDIDsResponse, err = didService.ListDIDsByMethod(context.Background(), did.ListDIDsRequest{Method: didsdk.KeyMethod}) - assert.NoError(tt, err) - assert.NotEmpty(tt, getDIDsResponse) - assert.Len(tt, getDIDsResponse.DIDs, 0) + assert.NoError(t, err) + assert.NotEmpty(t, getDIDsResponse) + assert.Len(t, getDIDsResponse.DIDs, 0) // get deleted DIDs back getDIDsResponse, err = didService.ListDIDsByMethod(context.Background(), did.ListDIDsRequest{Method: didsdk.KeyMethod, Deleted: true}) - assert.NoError(tt, err) - assert.NotEmpty(tt, getDIDsResponse) - assert.Len(tt, getDIDsResponse.DIDs, 2) + assert.NoError(t, err) + assert.NotEmpty(t, getDIDsResponse) + assert.Len(t, getDIDsResponse.DIDs, 2) }) - t.Run("DID Web Service Test", func(tt *testing.T) { - db := test.ServiceStorage(tt) - assert.NotEmpty(tt, db) + t.Run("DID Web Service Test", func(t *testing.T) { + db := test.ServiceStorage(t) + assert.NotEmpty(t, db) - keyStoreService := testKeyStoreService(tt, db) + keyStoreService := testKeyStoreService(t, db) methods := []string{didsdk.KeyMethod.String(), didsdk.WebMethod.String()} serviceConfig := config.DIDServiceConfig{Methods: methods, LocalResolutionMethods: methods} didService, err := did.NewDIDService(serviceConfig, db, keyStoreService, nil) - assert.NoError(tt, err) - assert.NotEmpty(tt, didService) + assert.NoError(t, err) + assert.NotEmpty(t, didService) // check type and status - assert.Equal(tt, framework.DID, didService.Type()) - assert.Equal(tt, framework.StatusReady, didService.Status().Status) + assert.Equal(t, framework.DID, didService.Type()) + assert.Equal(t, framework.StatusReady, didService.Status().Status) // get unknown handler _, err = didService.GetDIDByMethod(context.Background(), did.GetDIDRequest{Method: "bad"}) - assert.Error(tt, err) - assert.Contains(tt, err.Error(), "could not get handler for method") + assert.Error(t, err) + assert.Contains(t, err.Error(), "could not get handler for method") supported := didService.GetSupportedMethods() - assert.NotEmpty(tt, supported) - assert.Len(tt, supported.Methods, 2) + assert.NotEmpty(t, supported) + assert.Len(t, supported.Methods, 2) - assert.ElementsMatch(tt, supported.Methods, []didsdk.Method{didsdk.KeyMethod, didsdk.WebMethod}) + assert.ElementsMatch(t, supported.Methods, []didsdk.Method{didsdk.KeyMethod, didsdk.WebMethod}) gock.Off() gock.New("https://example.com"). @@ -198,8 +198,8 @@ func TestDIDRouter(t *testing.T) { // bad key type createOpts := did.CreateWebDIDOptions{DIDWebID: "did:web:example.com"} _, err = didService.CreateDIDByMethod(context.Background(), did.CreateDIDRequest{Method: didsdk.WebMethod, KeyType: "bad", Options: createOpts}) - assert.Error(tt, err) - assert.Contains(tt, err.Error(), "key type not supported") + assert.Error(t, err) + assert.Contains(t, err.Error(), "key type not supported") gock.Off() gock.New("https://example.com"). @@ -207,19 +207,19 @@ func TestDIDRouter(t *testing.T) { Reply(404) // good key type createDIDResponse, err := didService.CreateDIDByMethod(context.Background(), did.CreateDIDRequest{Method: didsdk.WebMethod, KeyType: crypto.Ed25519, Options: createOpts}) - assert.NoError(tt, err) - assert.NotEmpty(tt, createDIDResponse) + assert.NoError(t, err) + assert.NotEmpty(t, createDIDResponse) // check the DID is a did:key - assert.Contains(tt, createDIDResponse.DID.ID, "did:web") + assert.Contains(t, createDIDResponse.DID.ID, "did:web") // get it back getDIDResponse, err := didService.GetDIDByMethod(context.Background(), did.GetDIDRequest{Method: didsdk.WebMethod, ID: createDIDResponse.DID.ID}) - assert.NoError(tt, err) - assert.NotEmpty(tt, getDIDResponse) + assert.NoError(t, err) + assert.NotEmpty(t, getDIDResponse) // make sure it's the same value - assert.Equal(tt, createDIDResponse.DID.ID, getDIDResponse.DID.ID) + assert.Equal(t, createDIDResponse.DID.ID, getDIDResponse.DID.ID) gock.Off() gock.New("https://tbd.website"). @@ -228,44 +228,44 @@ func TestDIDRouter(t *testing.T) { // create a second DID createOpts = did.CreateWebDIDOptions{DIDWebID: "did:web:tbd.website"} createDIDResponse2, err := didService.CreateDIDByMethod(context.Background(), did.CreateDIDRequest{Method: didsdk.WebMethod, KeyType: crypto.Ed25519, Options: createOpts}) - assert.NoError(tt, err) - assert.NotEmpty(tt, createDIDResponse2) + assert.NoError(t, err) + assert.NotEmpty(t, createDIDResponse2) // get all DIDs back getDIDsResponse, err := didService.ListDIDsByMethod(context.Background(), did.ListDIDsRequest{Method: didsdk.WebMethod}) - assert.NoError(tt, err) - assert.NotEmpty(tt, getDIDsResponse) - assert.Len(tt, getDIDsResponse.DIDs, 2) + assert.NoError(t, err) + assert.NotEmpty(t, getDIDsResponse) + assert.Len(t, getDIDsResponse.DIDs, 2) knownDIDs := map[string]bool{createDIDResponse.DID.ID: true, createDIDResponse2.DID.ID: true} for _, gotDID := range getDIDsResponse.DIDs { if _, ok := knownDIDs[gotDID.ID]; !ok { - tt.Error("got unknown DID") + t.Error("got unknown DID") } else { delete(knownDIDs, gotDID.ID) } } - assert.Len(tt, knownDIDs, 0) + assert.Len(t, knownDIDs, 0) // delete dids err = didService.SoftDeleteDIDByMethod(context.Background(), did.DeleteDIDRequest{Method: didsdk.WebMethod, ID: createDIDResponse.DID.ID}) - assert.NoError(tt, err) + assert.NoError(t, err) err = didService.SoftDeleteDIDByMethod(context.Background(), did.DeleteDIDRequest{Method: didsdk.WebMethod, ID: createDIDResponse2.DID.ID}) - assert.NoError(tt, err) + assert.NoError(t, err) // get all DIDs back getDIDsResponse, err = didService.ListDIDsByMethod(context.Background(), did.ListDIDsRequest{Method: didsdk.WebMethod}) - assert.NoError(tt, err) - assert.NotEmpty(tt, getDIDsResponse) - assert.Len(tt, getDIDsResponse.DIDs, 0) + assert.NoError(t, err) + assert.NotEmpty(t, getDIDsResponse) + assert.Len(t, getDIDsResponse.DIDs, 0) }) }) } } -func createDID(tt *testing.T, didService *did.Service) { +func createDID(t *testing.T, didService *did.Service) { createDIDResponse, err := didService.CreateDIDByMethod(context.Background(), did.CreateDIDRequest{Method: didsdk.KeyMethod, KeyType: crypto.Ed25519}) - assert.NoError(tt, err) - assert.NotEmpty(tt, createDIDResponse) + assert.NoError(t, err) + assert.NotEmpty(t, createDIDResponse) } diff --git a/pkg/server/router/keystore_test.go b/pkg/server/router/keystore_test.go index df1e11633..edb17f90b 100644 --- a/pkg/server/router/keystore_test.go +++ b/pkg/server/router/keystore_test.go @@ -17,34 +17,34 @@ import ( func TestKeyStoreRouter(t *testing.T) { - t.Run("Nil Service", func(tt *testing.T) { + t.Run("Nil Service", func(t *testing.T) { keyStoreRouter, err := NewKeyStoreRouter(nil) - assert.Error(tt, err) - assert.Empty(tt, keyStoreRouter) - assert.Contains(tt, err.Error(), "service cannot be nil") + assert.Error(t, err) + assert.Empty(t, keyStoreRouter) + assert.Contains(t, err.Error(), "service cannot be nil") }) - t.Run("Bad Service", func(tt *testing.T) { + t.Run("Bad Service", func(t *testing.T) { keyStoreRouter, err := NewKeyStoreRouter(&testService{}) - assert.Error(tt, err) - assert.Empty(tt, keyStoreRouter) - assert.Contains(tt, err.Error(), "could not create key store router with service type: test") + assert.Error(t, err) + assert.Empty(t, keyStoreRouter) + assert.Contains(t, err.Error(), "could not create key store router with service type: test") }) for _, test := range testutil.TestDatabases { t.Run(test.Name, func(t *testing.T) { - t.Run("Key Store Service Test", func(tt *testing.T) { - db := test.ServiceStorage(tt) - assert.NotEmpty(tt, db) + t.Run("Key Store Service Test", func(t *testing.T) { + db := test.ServiceStorage(t) + assert.NotEmpty(t, db) serviceConfig := new(config.KeyStoreServiceConfig) keyStoreService, err := keystore.NewKeyStoreService(*serviceConfig, db) - assert.NoError(tt, err) - assert.NotEmpty(tt, keyStoreService) + assert.NoError(t, err) + assert.NotEmpty(t, keyStoreService) // check type and status - assert.Equal(tt, framework.KeyStore, keyStoreService.Type()) - assert.Equal(tt, framework.StatusReady, keyStoreService.Status().Status) + assert.Equal(t, framework.KeyStore, keyStoreService.Type()) + assert.Equal(t, framework.StatusReady, keyStoreService.Status().Status) // store an invalid key type err = keyStoreService.StoreKey(context.Background(), keystore.StoreKeyRequest{ @@ -53,47 +53,47 @@ func TestKeyStoreRouter(t *testing.T) { Controller: "me", PrivateKeyBase58: base58.Encode([]byte("bad")), }) - assert.Error(tt, err) - assert.Contains(tt, err.Error(), "unsupported key type: bad") + assert.Error(t, err) + assert.Contains(t, err.Error(), "unsupported key type: bad") // store a valid key _, privKey, err := crypto.GenerateKeyByKeyType(crypto.Ed25519) - assert.NoError(tt, err) - assert.NotEmpty(tt, privKey) + assert.NoError(t, err) + assert.NotEmpty(t, privKey) keyID := "did:test:me#key-1" privKeyBytes, err := crypto.PrivKeyToBytes(privKey) - assert.NoError(tt, err) + assert.NoError(t, err) err = keyStoreService.StoreKey(context.Background(), keystore.StoreKeyRequest{ ID: keyID, Type: crypto.Ed25519, Controller: "did:test:me", PrivateKeyBase58: base58.Encode(privKeyBytes), }) - assert.NoError(tt, err) + assert.NoError(t, err) // get a key that doesn't exist gotDetails, err := keyStoreService.GetKeyDetails(context.Background(), keystore.GetKeyDetailsRequest{ID: "bad"}) - assert.Error(tt, err) - assert.Empty(tt, gotDetails) - assert.Contains(tt, err.Error(), "could not get key details for key: bad") + assert.Error(t, err) + assert.Empty(t, gotDetails) + assert.Contains(t, err.Error(), "could not get key details for key: bad") // get a key that exists gotDetails, err = keyStoreService.GetKeyDetails(context.Background(), keystore.GetKeyDetailsRequest{ID: keyID}) - assert.NoError(tt, err) - assert.NotEmpty(tt, gotDetails) + assert.NoError(t, err) + assert.NotEmpty(t, gotDetails) // make sure the details match - assert.Equal(tt, keyID, gotDetails.ID) - assert.Equal(tt, crypto.Ed25519, gotDetails.Type) - assert.Equal(tt, "did:test:me", gotDetails.Controller) + assert.Equal(t, keyID, gotDetails.ID) + assert.Equal(t, crypto.Ed25519, gotDetails.Type) + assert.Equal(t, "did:test:me", gotDetails.Controller) // revoked key checks err = keyStoreService.RevokeKey(context.Background(), keystore.RevokeKeyRequest{ID: keyID}) - assert.NoError(tt, err) + assert.NoError(t, err) gotDetails, err = keyStoreService.GetKeyDetails(context.Background(), keystore.GetKeyDetailsRequest{ID: keyID}) - assert.NoError(tt, err) - assert.True(tt, gotDetails.Revoked) + assert.NoError(t, err) + assert.True(t, gotDetails.Revoked) }) }) } diff --git a/pkg/server/router/manifest_test.go b/pkg/server/router/manifest_test.go index 2eca08229..e79a260cc 100644 --- a/pkg/server/router/manifest_test.go +++ b/pkg/server/router/manifest_test.go @@ -29,46 +29,46 @@ import ( func TestManifestRouter(t *testing.T) { - t.Run("Nil Service", func(tt *testing.T) { + t.Run("Nil Service", func(t *testing.T) { manifestRouter, err := NewManifestRouter(nil) - assert.Error(tt, err) - assert.Empty(tt, manifestRouter) - assert.Contains(tt, err.Error(), "service cannot be nil") + assert.Error(t, err) + assert.Empty(t, manifestRouter) + assert.Contains(t, err.Error(), "service cannot be nil") }) - t.Run("Bad Service", func(tt *testing.T) { + t.Run("Bad Service", func(t *testing.T) { manifestRouter, err := NewManifestRouter(&testService{}) - assert.Error(tt, err) - assert.Empty(tt, manifestRouter) - assert.Contains(tt, err.Error(), "could not create manifest router with service type: test") + assert.Error(t, err) + assert.Empty(t, manifestRouter) + assert.Contains(t, err.Error(), "could not create manifest router with service type: test") }) for _, test := range testutil.TestDatabases { t.Run(test.Name, func(t *testing.T) { - t.Run("Manifest Service Test", func(tt *testing.T) { - db := test.ServiceStorage(tt) - assert.NotEmpty(tt, db) - - keyStoreService := testKeyStoreService(tt, db) - didService := testDIDService(tt, db, keyStoreService) - schemaService := testSchemaService(tt, db, keyStoreService, didService) - credentialService := testCredentialService(tt, db, keyStoreService, didService, schemaService) - presentationService := testPresentationDefinitionService(tt, db, didService, schemaService, keyStoreService) - manifestService := testManifestService(tt, db, keyStoreService, didService, credentialService, presentationService) - assert.NotEmpty(tt, manifestService) - - tt.Run("CreateManifest with presentation ID and value error", func(ttt *testing.T) { + t.Run("Manifest Service Test", func(t *testing.T) { + db := test.ServiceStorage(t) + assert.NotEmpty(t, db) + + keyStoreService := testKeyStoreService(t, db) + didService := testDIDService(t, db, keyStoreService) + schemaService := testSchemaService(t, db, keyStoreService, didService) + credentialService := testCredentialService(t, db, keyStoreService, didService, schemaService) + presentationService := testPresentationDefinitionService(t, db, didService, schemaService, keyStoreService) + manifestService := testManifestService(t, db, keyStoreService, didService, credentialService, presentationService) + assert.NotEmpty(t, manifestService) + + t.Run("CreateManifest with presentation ID and value error", func(t *testing.T) { defID := "an ID I know" createManifestRequest := getValidManifestRequest("did:ion:hello", "did:ion:hello#123", "schemaID") createManifestRequest.PresentationDefinitionRef.ID = &defID _, err := manifestService.CreateManifest(context.Background(), createManifestRequest) - assert.Error(ttt, err) - assert.ErrorContains(ttt, err, `only one of "id" and "value" can be provided`) + assert.Error(t, err) + assert.ErrorContains(t, err, `only one of "id" and "value" can be provided`) }) - tt.Run("CreateManifest with bad presentation ID returns error", func(ttt *testing.T) { + t.Run("CreateManifest with bad presentation ID returns error", func(t *testing.T) { defID := "a bad ID" createManifestRequest := getValidManifestRequest("did:ion:hello", "did:ion:hello#123", "schemaID") createManifestRequest.PresentationDefinitionRef = &model.PresentationDefinitionRef{ @@ -77,17 +77,17 @@ func TestManifestRouter(t *testing.T) { _, err := manifestService.CreateManifest(context.Background(), createManifestRequest) - assert.Error(ttt, err) - assert.ErrorContains(ttt, err, "presentation definition not found") + assert.Error(t, err) + assert.ErrorContains(t, err, "presentation definition not found") }) - tt.Run("CreateManifest with presentation ID returns manifest", func(ttt *testing.T) { - definition := createPresentationDefinition(ttt) + t.Run("CreateManifest with presentation ID returns manifest", func(t *testing.T) { + definition := createPresentationDefinition(t) resp, err := presentationService.CreatePresentationDefinition(context.Background(), presmodel.CreatePresentationDefinitionRequest{ PresentationDefinition: *definition, }) - assert.NoError(ttt, err) - assert.NotEmpty(ttt, resp) + assert.NoError(t, err) + assert.NotEmpty(t, resp) createManifestRequest := getValidManifestRequest("did:ion:hello", "did:ion:hello#123", "schemaID") createManifestRequest.PresentationDefinitionRef = &model.PresentationDefinitionRef{ @@ -95,14 +95,14 @@ func TestManifestRouter(t *testing.T) { } createdManifest, err := manifestService.CreateManifest(context.Background(), createManifestRequest) - assert.NoError(ttt, err) - assert.Equal(ttt, resp.PresentationDefinition, *createdManifest.Manifest.PresentationDefinition) + assert.NoError(t, err) + assert.Equal(t, resp.PresentationDefinition, *createdManifest.Manifest.PresentationDefinition) }) - tt.Run("multiple behaviors", func(ttt *testing.T) { + t.Run("multiple behaviors", func(t *testing.T) { // check type and status - assert.Equal(ttt, framework.Manifest, manifestService.Type()) - assert.Equal(ttt, framework.StatusReady, manifestService.Status().Status) + assert.Equal(t, framework.Manifest, manifestService.Type()) + assert.Equal(t, framework.StatusReady, manifestService.Status().Status) // create issuer and applicant DIDs createDIDRequest := did.CreateDIDRequest{ @@ -110,17 +110,17 @@ func TestManifestRouter(t *testing.T) { KeyType: crypto.Ed25519, } issuerDID, err := didService.CreateDIDByMethod(context.Background(), createDIDRequest) - assert.NoError(ttt, err) - assert.NotEmpty(ttt, issuerDID) + assert.NoError(t, err) + assert.NotEmpty(t, issuerDID) applicantPrivKey, applicantDIDKey, err := key.GenerateDIDKey(crypto.Ed25519) - assert.NoError(ttt, err) - assert.NotEmpty(ttt, applicantPrivKey) - assert.NotEmpty(ttt, applicantDIDKey) + assert.NoError(t, err) + assert.NotEmpty(t, applicantPrivKey) + assert.NotEmpty(t, applicantDIDKey) applicantDID, err := applicantDIDKey.Expand() - assert.NoError(ttt, err) - assert.NotEmpty(ttt, applicantDID) + assert.NoError(t, err) + assert.NotEmpty(t, applicantDID) // create a schema for the creds to be issued against licenseSchema := map[string]any{ @@ -143,8 +143,8 @@ func TestManifestRouter(t *testing.T) { } kid := issuerDID.DID.VerificationMethod[0].ID createdSchema, err := schemaService.CreateSchema(context.Background(), schema.CreateSchemaRequest{Issuer: issuerDID.DID.ID, FullyQualifiedVerificationMethodID: kid, Name: "license schema", Schema: licenseSchema}) - assert.NoError(ttt, err) - assert.NotEmpty(ttt, createdSchema) + assert.NoError(t, err) + assert.NotEmpty(t, createdSchema) // issue a credential against the schema to the subject, from the issuer createdCred, err := credentialService.CreateCredential(context.Background(), credential.CreateCredentialRequest{ @@ -154,20 +154,20 @@ func TestManifestRouter(t *testing.T) { SchemaID: createdSchema.ID, Data: map[string]any{"licenseType": "WA-DL-CLASS-A"}, }) - assert.NoError(ttt, err) - assert.NotEmpty(ttt, createdCred) + assert.NoError(t, err) + assert.NotEmpty(t, createdCred) // good manifest request, which asks for a single verifiable credential in the VC-JWT format createManifestRequest := getValidManifestRequest(issuerDID.DID.ID, kid, createdSchema.ID) createdManifest, err := manifestService.CreateManifest(context.Background(), createManifestRequest) - assert.NoError(ttt, err) - assert.NotEmpty(ttt, createdManifest) + assert.NoError(t, err) + assert.NotEmpty(t, createdManifest) manifestRequestRequest := getValidManifestRequestRequest(issuerDID, kid, createdManifest) manifestRequest, err := manifestService.CreateRequest(context.Background(), manifestRequestRequest) - assert.NoError(ttt, err) - assert.Equal(ttt, createdManifest.Manifest.ID, manifestRequest.ManifestID) - assert.NotEmpty(ttt, manifestRequest.CredentialManifestJWT.String()) + assert.NoError(t, err) + assert.Equal(t, createdManifest.Manifest.ID, manifestRequest.ManifestID) + assert.NotEmpty(t, manifestRequest.CredentialManifestJWT.String()) got, err := manifestService.GetRequest(context.Background(), &model.GetRequestRequest{ID: manifestRequest.ID}) assert.NoError(t, err) @@ -181,12 +181,12 @@ func TestManifestRouter(t *testing.T) { assert.ErrorContains(t, err, "request not found") verificationResponse, err := manifestService.VerifyManifest(context.Background(), model.VerifyManifestRequest{ManifestJWT: manifestRequest.CredentialManifestJWT}) - assert.NoError(ttt, err) - assert.NotEmpty(ttt, verificationResponse) - assert.True(ttt, verificationResponse.Verified) + assert.NoError(t, err) + assert.NotEmpty(t, verificationResponse) + assert.True(t, verificationResponse.Verified) m := createdManifest.Manifest - assert.NotEmpty(ttt, m) + assert.NotEmpty(t, m) // good application request containers := []credmodel.Container{{ @@ -197,38 +197,38 @@ func TestManifestRouter(t *testing.T) { // sign application signer, err := keyaccess.NewJWKKeyAccess(applicantDID.ID, applicantDID.VerificationMethod[0].ID, applicantPrivKey) - assert.NoError(ttt, err) + assert.NoError(t, err) signed, err := signer.SignJSON(applicationRequest) - assert.NoError(ttt, err) + assert.NoError(t, err) // submit and review application, the key is valid - createdApplicationResponse, err := submitAndReviewApplication(signed, ttt, manifestService) - assert.NoError(ttt, err) - assert.NotEmpty(ttt, createdManifest) - assert.NotEmpty(ttt, createdApplicationResponse.Response.ID) - assert.NotEmpty(ttt, createdApplicationResponse.Response.Fulfillment) - assert.Empty(ttt, createdApplicationResponse.Response.Denial) - assert.Equal(ttt, len(createManifestRequest.OutputDescriptors), len(createdApplicationResponse.Credentials)) - - // attempt to submit and review application again, this time with the revoked key + createdApplicationResponse, err := submitAndReviewApplication(signed, t, manifestService) + assert.NoError(t, err) + assert.NotEmpty(t, createdManifest) + assert.NotEmpty(t, createdApplicationResponse.Response.ID) + assert.NotEmpty(t, createdApplicationResponse.Response.Fulfillment) + assert.Empty(t, createdApplicationResponse.Response.Denial) + assert.Equal(t, len(createManifestRequest.OutputDescriptors), len(createdApplicationResponse.Credentials)) + + // atempt to submit and review application again, this time with the revoked key err = keyStoreService.RevokeKey(context.Background(), keystore.RevokeKeyRequest{ID: kid}) - assert.NoError(ttt, err) - _, err = submitAndReviewApplication(signed, ttt, manifestService) - assert.Error(tt, err) - assert.ErrorContains(tt, err, "cannot use revoked key") + assert.NoError(t, err) + _, err = submitAndReviewApplication(signed, t, manifestService) + assert.Error(t, err) + assert.ErrorContains(t, err, "cannot use revoked key") }) }) }) } } -func submitAndReviewApplication(signed *keyaccess.JWT, ttt *testing.T, manifestService *manifest.Service) (*model.SubmitApplicationResponse, error) { +func submitAndReviewApplication(signed *keyaccess.JWT, t *testing.T, manifestService *manifest.Service) (*model.SubmitApplicationResponse, error) { submitApplicationRequest := SubmitApplicationRequest{ApplicationJWT: *signed} sar, err := submitApplicationRequest.toServiceRequest() - assert.NoError(ttt, err) + assert.NoError(t, err) createdApplicationResponseOp, err := manifestService.ProcessApplicationSubmission(context.Background(), *sar) - assert.NoError(ttt, err) - assert.False(ttt, createdApplicationResponseOp.Done) + assert.NoError(t, err) + assert.False(t, createdApplicationResponseOp.Done) createdApplicationResponse, err := manifestService.ReviewApplication(context.Background(), model.ReviewApplicationRequest{ ID: storage.StatusObjectID(createdApplicationResponseOp.ID), diff --git a/pkg/server/router/presentation_test.go b/pkg/server/router/presentation_test.go index 6a5dc840f..b8e4e6431 100644 --- a/pkg/server/router/presentation_test.go +++ b/pkg/server/router/presentation_test.go @@ -23,18 +23,18 @@ import ( ) func TestPresentationDefinitionRouter(t *testing.T) { - t.Run("Nil Service", func(tt *testing.T) { + t.Run("Nil Service", func(t *testing.T) { pdRouter, err := NewPresentationRouter(nil) - assert.Error(tt, err) - assert.Empty(tt, pdRouter) - assert.Contains(tt, err.Error(), "service cannot be nil") + assert.Error(t, err) + assert.Empty(t, pdRouter) + assert.Contains(t, err.Error(), "service cannot be nil") }) - t.Run("Bad Service", func(tt *testing.T) { + t.Run("Bad Service", func(t *testing.T) { pdRouter, err := NewPresentationRouter(&testService{}) - assert.Error(tt, err) - assert.Empty(tt, pdRouter) - assert.Contains(tt, err.Error(), "could not create presentation router with service type: test") + assert.Error(t, err) + assert.Empty(t, pdRouter) + assert.Contains(t, err.Error(), "could not create presentation router with service type: test") }) } diff --git a/pkg/server/router/schema_test.go b/pkg/server/router/schema_test.go index b94d79dfc..c433ec617 100644 --- a/pkg/server/router/schema_test.go +++ b/pkg/server/router/schema_test.go @@ -18,93 +18,93 @@ import ( func TestSchemaRouter(t *testing.T) { - t.Run("Nil Service", func(tt *testing.T) { + t.Run("Nil Service", func(t *testing.T) { schemaRouter, err := NewSchemaRouter(nil) - assert.Error(tt, err) - assert.Empty(tt, schemaRouter) - assert.Contains(tt, err.Error(), "service cannot be nil") + assert.Error(t, err) + assert.Empty(t, schemaRouter) + assert.Contains(t, err.Error(), "service cannot be nil") }) - t.Run("Bad Service", func(tt *testing.T) { + t.Run("Bad Service", func(t *testing.T) { schemaRouter, err := NewSchemaRouter(&testService{}) - assert.Error(tt, err) - assert.Empty(tt, schemaRouter) - assert.Contains(tt, err.Error(), "could not create schema router with service type: test") + assert.Error(t, err) + assert.Empty(t, schemaRouter) + assert.Contains(t, err.Error(), "could not create schema router with service type: test") }) for _, test := range testutil.TestDatabases { t.Run(test.Name, func(t *testing.T) { - t.Run("Schema Service Test", func(tt *testing.T) { - db := test.ServiceStorage(tt) - assert.NotEmpty(tt, db) + t.Run("Schema Service Test", func(t *testing.T) { + db := test.ServiceStorage(t) + assert.NotEmpty(t, db) - keyStoreService := testKeyStoreService(tt, db) - didService := testDIDService(tt, db, keyStoreService) + keyStoreService := testKeyStoreService(t, db) + didService := testDIDService(t, db, keyStoreService) schemaService, err := schema.NewSchemaService(db, keyStoreService, didService.GetResolver()) - assert.NoError(tt, err) - assert.NotEmpty(tt, schemaService) + assert.NoError(t, err) + assert.NotEmpty(t, schemaService) // check type and status - assert.Equal(tt, framework.Schema, schemaService.Type()) - assert.Equal(tt, framework.StatusReady, schemaService.Status().Status) + assert.Equal(t, framework.Schema, schemaService.Type()) + assert.Equal(t, framework.StatusReady, schemaService.Status().Status) // get all schemas (none) gotSchemas, err := schemaService.ListSchemas(context.Background(), schema.ListSchemasRequest{}) - assert.NoError(tt, err) - assert.Empty(tt, gotSchemas.Schemas) + assert.NoError(t, err) + assert.Empty(t, gotSchemas.Schemas) // get schema that doesn't exist _, err = schemaService.GetSchema(context.Background(), schema.GetSchemaRequest{ID: "bad"}) - assert.Error(tt, err) - assert.Contains(tt, err.Error(), "error getting schema") + assert.Error(t, err) + assert.Contains(t, err.Error(), "error getting schema") // create a schema simpleSchema := getSimpleSchema() createdSchema, err := schemaService.CreateSchema(context.Background(), schema.CreateSchemaRequest{Issuer: "me", Name: "simple schema", Schema: simpleSchema}) - assert.NoError(tt, err) - assert.NotEmpty(tt, createdSchema) - assert.NotEmpty(tt, createdSchema.ID) - assert.Equal(tt, "simple schema", createdSchema.Schema.Name()) + assert.NoError(t, err) + assert.NotEmpty(t, createdSchema) + assert.NotEmpty(t, createdSchema.ID) + assert.Equal(t, "simple schema", createdSchema.Schema.Name()) // get schema by ID gotSchema, err := schemaService.GetSchema(context.Background(), schema.GetSchemaRequest{ID: createdSchema.ID}) - assert.NoError(tt, err) - assert.NotEmpty(tt, gotSchema) - assert.EqualValues(tt, createdSchema.Schema, gotSchema.Schema) + assert.NoError(t, err) + assert.NotEmpty(t, gotSchema) + assert.EqualValues(t, createdSchema.Schema, gotSchema.Schema) // get all schemas, expect one gotSchemas, err = schemaService.ListSchemas(context.Background(), schema.ListSchemasRequest{}) - assert.NoError(tt, err) - assert.NotEmpty(tt, gotSchemas.Schemas) - assert.Len(tt, gotSchemas.Schemas, 1) + assert.NoError(t, err) + assert.NotEmpty(t, gotSchemas.Schemas) + assert.Len(t, gotSchemas.Schemas, 1) // store another createdSchema, err = schemaService.CreateSchema(context.Background(), schema.CreateSchemaRequest{Issuer: "me", Name: "simple schema 2", Schema: simpleSchema}) - assert.NoError(tt, err) - assert.NotEmpty(tt, createdSchema) - assert.NotEmpty(tt, createdSchema.ID) - assert.Equal(tt, "simple schema 2", createdSchema.Schema.Name()) - assert.Equal(tt, credschema.JSONSchemaType, createdSchema.Type) + assert.NoError(t, err) + assert.NotEmpty(t, createdSchema) + assert.NotEmpty(t, createdSchema.ID) + assert.Equal(t, "simple schema 2", createdSchema.Schema.Name()) + assert.Equal(t, credschema.JSONSchemaType, createdSchema.Type) // get all schemas, expect two gotSchemas, err = schemaService.ListSchemas(context.Background(), schema.ListSchemasRequest{}) - assert.NoError(tt, err) - assert.NotEmpty(tt, gotSchemas.Schemas) - assert.Len(tt, gotSchemas.Schemas, 2) + assert.NoError(t, err) + assert.NotEmpty(t, gotSchemas.Schemas) + assert.Len(t, gotSchemas.Schemas, 2) // make sure their IDs are different - assert.True(tt, gotSchemas.Schemas[0].ID != gotSchemas.Schemas[1].ID) + assert.True(t, gotSchemas.Schemas[0].ID != gotSchemas.Schemas[1].ID) // delete the first schema err = schemaService.DeleteSchema(context.Background(), schema.DeleteSchemaRequest{ID: gotSchemas.Schemas[0].ID}) - assert.NoError(tt, err) + assert.NoError(t, err) // get all schemas, expect one gotSchemas, err = schemaService.ListSchemas(context.Background(), schema.ListSchemasRequest{}) - assert.NoError(tt, err) - assert.NotEmpty(tt, gotSchemas.Schemas) - assert.Len(tt, gotSchemas.Schemas, 1) + assert.NoError(t, err) + assert.NotEmpty(t, gotSchemas.Schemas) + assert.Len(t, gotSchemas.Schemas, 1) }) }) } @@ -114,44 +114,44 @@ func TestSchemaSigning(t *testing.T) { for _, test := range testutil.TestDatabases { t.Run(test.Name, func(t *testing.T) { - t.Run("Unsigned Schema Test", func(tt *testing.T) { - db := test.ServiceStorage(tt) - assert.NotEmpty(tt, db) + t.Run("Unsigned Schema Test", func(t *testing.T) { + db := test.ServiceStorage(t) + assert.NotEmpty(t, db) - keyStoreService := testKeyStoreService(tt, db) - didService := testDIDService(tt, db, keyStoreService) + keyStoreService := testKeyStoreService(t, db) + didService := testDIDService(t, db, keyStoreService) schemaService, err := schema.NewSchemaService(db, keyStoreService, didService.GetResolver()) - assert.NoError(tt, err) - assert.NotEmpty(tt, schemaService) + assert.NoError(t, err) + assert.NotEmpty(t, schemaService) // check type and status - assert.Equal(tt, framework.Schema, schemaService.Type()) - assert.Equal(tt, framework.StatusReady, schemaService.Status().Status) + assert.Equal(t, framework.Schema, schemaService.Type()) + assert.Equal(t, framework.StatusReady, schemaService.Status().Status) // create a schema and don't sign it simpleSchema := getSimpleSchema() createdSchema, err := schemaService.CreateSchema(context.Background(), schema.CreateSchemaRequest{Issuer: "me", Name: "simple schema", Schema: simpleSchema}) - assert.NoError(tt, err) - assert.NotEmpty(tt, createdSchema) - assert.NotEmpty(tt, createdSchema.ID) - assert.Equal(tt, "simple schema", createdSchema.Schema.Name()) + assert.NoError(t, err) + assert.NotEmpty(t, createdSchema) + assert.NotEmpty(t, createdSchema.ID) + assert.Equal(t, "simple schema", createdSchema.Schema.Name()) }) }) - t.Run("Signing schema with revoked key test", func(tt *testing.T) { - db := test.ServiceStorage(tt) - assert.NotEmpty(tt, db) + t.Run("Signing schema with revoked key test", func(t *testing.T) { + db := test.ServiceStorage(t) + assert.NotEmpty(t, db) - keyStoreService := testKeyStoreService(tt, db) - didService := testDIDService(tt, db, keyStoreService) + keyStoreService := testKeyStoreService(t, db) + didService := testDIDService(t, db, keyStoreService) schemaService, err := schema.NewSchemaService(db, keyStoreService, didService.GetResolver()) - assert.NoError(tt, err) - assert.NotEmpty(tt, schemaService) + assert.NoError(t, err) + assert.NotEmpty(t, schemaService) // Create a DID controllerDID, err := didService.CreateDIDByMethod(context.Background(), did.CreateDIDRequest{Method: didsdk.KeyMethod, KeyType: crypto.Ed25519}) - assert.NoError(tt, err) - assert.NotEmpty(tt, controllerDID) + assert.NoError(t, err) + assert.NotEmpty(t, controllerDID) didID := controllerDID.DID.ID // Create a key controlled by the DID @@ -159,16 +159,16 @@ func TestSchemaSigning(t *testing.T) { privateKey := "2dEPd7mA3aiuh2gky8tTPiCkyMwf8tBNUMZwRzeVxVJnJFGTbdLGUBcx51DCNyFWRjTG9bduvyLRStXSCDMFXULY" err = keyStoreService.StoreKey(context.Background(), keystore.StoreKeyRequest{ID: keyID, Type: crypto.Ed25519, Controller: didID, PrivateKeyBase58: privateKey}) - assert.NoError(tt, err) + assert.NoError(t, err) // Revoke the key err = keyStoreService.RevokeKey(context.Background(), keystore.RevokeKeyRequest{ID: keyID}) - assert.NoError(tt, err) + assert.NoError(t, err) // create a schema with the revoked key, it fails _, err = schemaService.CreateSchema(context.Background(), schema.CreateSchemaRequest{Issuer: controllerDID.DID.ID, Name: "schema (revoked key)", Schema: getEmailSchema(), FullyQualifiedVerificationMethodID: keyID}) - assert.Error(tt, err) - assert.ErrorContains(tt, err, "cannot use revoked key") + assert.Error(t, err) + assert.ErrorContains(t, err, "cannot use revoked key") }) } } diff --git a/pkg/server/router/webhook_test.go b/pkg/server/router/webhook_test.go index 15ea44141..058fa31d4 100644 --- a/pkg/server/router/webhook_test.go +++ b/pkg/server/router/webhook_test.go @@ -13,34 +13,36 @@ import ( ) func TestWebhookRouter(t *testing.T) { - t.Run("Nil Service", func(tt *testing.T) { + t.Run("Nil Service", func(t *testing.T) { webhookRouter, err := NewWebhookRouter(nil) - assert.Error(tt, err) - assert.Empty(tt, webhookRouter) - assert.Contains(tt, err.Error(), "service cannot be nil") + assert.Error(t, err) + assert.Empty(t, webhookRouter) + assert.Contains(t, err.Error(), "service cannot be nil") }) - t.Run("Bad Service", func(tt *testing.T) { + t.Run("Bad Service", func(t *testing.T) { webhookRouter, err := NewWebhookRouter(&testService{}) - assert.Error(tt, err) - assert.Empty(tt, webhookRouter) - assert.Contains(tt, err.Error(), "could not create webhook router with service type: test") + assert.Error(t, err) + assert.Empty(t, webhookRouter) + assert.Contains(t, err.Error(), "could not create webhook router with service type: test") }) +} +func TestWebhookService(t *testing.T) { for _, test := range testutil.TestDatabases { t.Run(test.Name, func(t *testing.T) { - t.Run("Webhook Service Test", func(tt *testing.T) { - db := test.ServiceStorage(tt) - require.NotEmpty(tt, db) + t.Run("Webhook Service Test", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) serviceConfig := config.WebhookServiceConfig{WebhookTimeout: "10s"} webhookService, err := webhook.NewWebhookService(serviceConfig, db) - assert.NoError(tt, err) - assert.NotEmpty(tt, webhookService) + assert.NoError(t, err) + assert.NotEmpty(t, webhookService) // check type and status - assert.Equal(tt, framework.Webhook, webhookService.Type()) - assert.Equal(tt, framework.StatusReady, webhookService.Status().Status) + assert.Equal(t, framework.Webhook, webhookService.Type()) + assert.Equal(t, framework.StatusReady, webhookService.Status().Status) }) }) } diff --git a/pkg/server/server_credential_test.go b/pkg/server/server_credential_test.go index c1fe6cc10..a8df282b5 100644 --- a/pkg/server/server_credential_test.go +++ b/pkg/server/server_credential_test.go @@ -31,22 +31,22 @@ import ( func TestCredentialAPI(t *testing.T) { for _, test := range testutil.TestDatabases { - t.Run(test.Name, func(tt *testing.T) { - tt.Run("Batch Update Credential Status", func(ttt *testing.T) { - db := test.ServiceStorage(ttt) - require.NotEmpty(ttt, db) + t.Run(test.Name, func(t *testing.T) { + t.Run("Batch Update Credential Status", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - keyStoreService, _ := testKeyStoreService(ttt, db) - didService, _ := testDIDService(ttt, db, keyStoreService, nil) - schemaService := testSchemaService(ttt, db, keyStoreService, didService) - credRouter := testCredentialRouter(ttt, db, keyStoreService, didService, schemaService) + keyStoreService, _ := testKeyStoreService(t, db) + didService, _ := testDIDService(t, db, keyStoreService, nil) + schemaService := testSchemaService(t, db, keyStoreService, didService) + credRouter := testCredentialRouter(t, db, keyStoreService, didService, schemaService) issuerDID, err := didService.CreateDIDByMethod(context.Background(), did.CreateDIDRequest{ Method: didsdk.KeyMethod, KeyType: crypto.Ed25519, }) - assert.NoError(ttt, err) - assert.NotEmpty(ttt, issuerDID) + assert.NoError(t, err) + assert.NotEmpty(t, issuerDID) batchCreateCredentialsRequest := router.BatchCreateCredentialsRequest{ Requests: []router.CreateCredentialRequest{ @@ -82,18 +82,18 @@ func TestCredentialAPI(t *testing.T) { }, }, } - requestValue := newRequestValue(ttt, batchCreateCredentialsRequest) + requestValue := newRequestValue(t, batchCreateCredentialsRequest) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/credentials/batch", requestValue) w := httptest.NewRecorder() c := newRequestContext(w, req) credRouter.BatchCreateCredentials(c) - assert.True(ttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.BatchCreateCredentialsResponse err = json.NewDecoder(w.Body).Decode(&resp) - assert.NoError(ttt, err) + assert.NoError(t, err) - assert.Len(ttt, resp.Credentials, 3) + assert.Len(t, resp.Credentials, 3) // Now we got to updates updateCredStatusRequest := router.BatchUpdateCredentialStatusRequest{ @@ -119,121 +119,121 @@ func TestCredentialAPI(t *testing.T) { }, } - ttt.Run("empty batch returns success", func(ttt *testing.T) { - requestValue = newRequestValue(ttt, router.BatchUpdateCredentialStatusRequest{ + t.Run("empty batch returns success", func(t *testing.T) { + requestValue = newRequestValue(t, router.BatchUpdateCredentialStatusRequest{ Requests: []router.SingleUpdateCredentialStatusRequest{}, }) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/credentials/status/batch", requestValue) w = httptest.NewRecorder() c = newRequestContext(w, req) credRouter.BatchUpdateCredentialStatus(c) - assert.True(ttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) }) - ttt.Run("all credentials are updated", func(ttt *testing.T) { - requestValue = newRequestValue(ttt, updateCredStatusRequest) + t.Run("all credentials are updated", func(t *testing.T) { + requestValue = newRequestValue(t, updateCredStatusRequest) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/credentials/status/batch", requestValue) w = httptest.NewRecorder() c = newRequestContext(w, req) credRouter.BatchUpdateCredentialStatus(c) - assert.True(ttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var credStatusUpdateResponse router.BatchUpdateCredentialStatusResponse err = json.NewDecoder(w.Body).Decode(&credStatusUpdateResponse) - assert.NoError(ttt, err) + assert.NoError(t, err) - assert.Len(ttt, credStatusUpdateResponse.CredentialStatuses, 3) - assert.True(ttt, credStatusUpdateResponse.CredentialStatuses[0].Suspended) - assert.True(ttt, credStatusUpdateResponse.CredentialStatuses[1].Revoked) - assert.True(ttt, credStatusUpdateResponse.CredentialStatuses[2].Suspended) + assert.Len(t, credStatusUpdateResponse.CredentialStatuses, 3) + assert.True(t, credStatusUpdateResponse.CredentialStatuses[0].Suspended) + assert.True(t, credStatusUpdateResponse.CredentialStatuses[1].Revoked) + assert.True(t, credStatusUpdateResponse.CredentialStatuses[2].Suspended) }) - ttt.Run("updates are idempotent", func(ttt *testing.T) { - requestValue = newRequestValue(ttt, updateCredStatusRequest) + t.Run("updates are idempotent", func(t *testing.T) { + requestValue = newRequestValue(t, updateCredStatusRequest) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/credentials/status/batch", requestValue) w = httptest.NewRecorder() c = newRequestContext(w, req) credRouter.BatchUpdateCredentialStatus(c) - assert.True(ttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var credStatusUpdateResponse router.BatchUpdateCredentialStatusResponse err = json.NewDecoder(w.Body).Decode(&credStatusUpdateResponse) - assert.NoError(ttt, err) + assert.NoError(t, err) - assert.Len(ttt, credStatusUpdateResponse.CredentialStatuses, 3) - assert.True(ttt, credStatusUpdateResponse.CredentialStatuses[0].Suspended) - assert.True(ttt, credStatusUpdateResponse.CredentialStatuses[1].Revoked) - assert.True(ttt, credStatusUpdateResponse.CredentialStatuses[2].Suspended) + assert.Len(t, credStatusUpdateResponse.CredentialStatuses, 3) + assert.True(t, credStatusUpdateResponse.CredentialStatuses[0].Suspended) + assert.True(t, credStatusUpdateResponse.CredentialStatuses[1].Revoked) + assert.True(t, credStatusUpdateResponse.CredentialStatuses[2].Suspended) }) - ttt.Run("missing ID fails", func(ttt *testing.T) { + t.Run("missing ID fails", func(t *testing.T) { updateCredStatusRequest := deepcopy.Copy(updateCredStatusRequest).(router.BatchUpdateCredentialStatusRequest) updateCredStatusRequest.Requests[0].ID = "" - requestValue = newRequestValue(ttt, updateCredStatusRequest) + requestValue = newRequestValue(t, updateCredStatusRequest) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/credentials/status/batch", requestValue) w = httptest.NewRecorder() c = newRequestContext(w, req) credRouter.BatchUpdateCredentialStatus(c) - assert.False(ttt, util.Is2xxResponse(w.Code)) + assert.False(t, util.Is2xxResponse(w.Code)) var errJSON map[string]any err = json.NewDecoder(w.Body).Decode(&errJSON) - assert.NoError(ttt, err) + assert.NoError(t, err) - assert.Contains(ttt, errJSON["error"], "field validation error") + assert.Contains(t, errJSON["error"], "field validation error") }) - ttt.Run("second credential does not exist", func(ttt *testing.T) { + t.Run("second credential does not exist", func(t *testing.T) { updateCredStatusRequest := deepcopy.Copy(updateCredStatusRequest).(router.BatchUpdateCredentialStatusRequest) updateCredStatusRequest.Requests[1].ID = "made up id 1" - requestValue = newRequestValue(ttt, updateCredStatusRequest) + requestValue = newRequestValue(t, updateCredStatusRequest) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/credentials/status/batch", requestValue) w = httptest.NewRecorder() c = newRequestContext(w, req) credRouter.BatchUpdateCredentialStatus(c) - assert.False(ttt, util.Is2xxResponse(w.Code)) + assert.False(t, util.Is2xxResponse(w.Code)) var errJSON map[string]any err = json.NewDecoder(w.Body).Decode(&errJSON) - assert.NoError(ttt, err) + assert.NoError(t, err) - assert.Contains(ttt, errJSON["error"], "credential not found with id: made up id 1") + assert.Contains(t, errJSON["error"], "credential not found with id: made up id 1") }) - ttt.Run("revoking a suspendable credential returns error", func(ttt *testing.T) { + t.Run("revoking a suspendable credential returns error", func(t *testing.T) { updateCredStatusRequest := deepcopy.Copy(updateCredStatusRequest).(router.BatchUpdateCredentialStatusRequest) updateCredStatusRequest.Requests[2].Revoked = true updateCredStatusRequest.Requests[2].Suspended = false - requestValue = newRequestValue(ttt, updateCredStatusRequest) + requestValue = newRequestValue(t, updateCredStatusRequest) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/credentials/status/batch", requestValue) w = httptest.NewRecorder() c = newRequestContext(w, req) credRouter.BatchUpdateCredentialStatus(c) - assert.False(ttt, util.Is2xxResponse(w.Code)) + assert.False(t, util.Is2xxResponse(w.Code)) var errJSON map[string]any err = json.NewDecoder(w.Body).Decode(&errJSON) - assert.NoError(ttt, err) + assert.NoError(t, err) - assert.Contains(ttt, errJSON["error"], "has a different status purpose value than the status credential") + assert.Contains(t, errJSON["error"], "has a different status purpose value than the status credential") }) }) - tt.Run("Batch Create Credentials", func(ttt *testing.T) { - db := test.ServiceStorage(ttt) - require.NotEmpty(ttt, db) + t.Run("Batch Create Credentials", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - keyStoreService, _ := testKeyStoreService(ttt, db) - didService, _ := testDIDService(ttt, db, keyStoreService, nil) - schemaService := testSchemaService(ttt, db, keyStoreService, didService) - credRouter := testCredentialRouter(ttt, db, keyStoreService, didService, schemaService) + keyStoreService, _ := testKeyStoreService(t, db) + didService, _ := testDIDService(t, db, keyStoreService, nil) + schemaService := testSchemaService(t, db, keyStoreService, didService) + credRouter := testCredentialRouter(t, db, keyStoreService, didService, schemaService) issuerDID, err := didService.CreateDIDByMethod(context.Background(), did.CreateDIDRequest{ Method: didsdk.KeyMethod, KeyType: crypto.Ed25519, }) - assert.NoError(ttt, err) - assert.NotEmpty(ttt, issuerDID) + assert.NoError(t, err) + assert.NotEmpty(t, issuerDID) batchCreateCredentialsRequest := router.BatchCreateCredentialsRequest{ Requests: []router.CreateCredentialRequest{ @@ -260,36 +260,36 @@ func TestCredentialAPI(t *testing.T) { }, }, } - ttt.Run("Returns Many Credentials", func(ttt *testing.T) { - requestValue := newRequestValue(ttt, batchCreateCredentialsRequest) + t.Run("Returns Many Credentials", func(t *testing.T) { + requestValue := newRequestValue(t, batchCreateCredentialsRequest) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/credentials/batch", requestValue) w := httptest.NewRecorder() c := newRequestContext(w, req) credRouter.BatchCreateCredentials(c) - assert.True(ttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.BatchCreateCredentialsResponse err = json.NewDecoder(w.Body).Decode(&resp) - assert.NoError(ttt, err) - - assert.Len(ttt, resp.Credentials, 2) - - assert.NotEmpty(ttt, resp.Credentials[0].CredentialJWT) - assert.Equal(ttt, resp.Credentials[0].Credential.Issuer, issuerDID.DID.ID) - assert.Equal(ttt, "did:abc:456", resp.Credentials[0].Credential.CredentialSubject.GetID()) - assert.Equal(ttt, "Jack", resp.Credentials[0].Credential.CredentialSubject["firstName"]) - assert.Equal(ttt, "Dorsey", resp.Credentials[0].Credential.CredentialSubject["lastName"]) - assert.Empty(ttt, resp.Credentials[0].Credential.CredentialStatus) - - assert.NotEmpty(ttt, resp.Credentials[1].CredentialJWT) - assert.Equal(ttt, resp.Credentials[1].Credential.Issuer, issuerDID.DID.ID) - assert.Equal(ttt, "did:abc:789", resp.Credentials[1].Credential.CredentialSubject.GetID()) - assert.Equal(ttt, "Lemony", resp.Credentials[1].Credential.CredentialSubject["firstName"]) - assert.Equal(ttt, "Snickets", resp.Credentials[1].Credential.CredentialSubject["lastName"]) - assert.NotEmpty(ttt, resp.Credentials[1].Credential.CredentialStatus) + assert.NoError(t, err) + + assert.Len(t, resp.Credentials, 2) + + assert.NotEmpty(t, resp.Credentials[0].CredentialJWT) + assert.Equal(t, resp.Credentials[0].Credential.Issuer, issuerDID.DID.ID) + assert.Equal(t, "did:abc:456", resp.Credentials[0].Credential.CredentialSubject.GetID()) + assert.Equal(t, "Jack", resp.Credentials[0].Credential.CredentialSubject["firstName"]) + assert.Equal(t, "Dorsey", resp.Credentials[0].Credential.CredentialSubject["lastName"]) + assert.Empty(t, resp.Credentials[0].Credential.CredentialStatus) + + assert.NotEmpty(t, resp.Credentials[1].CredentialJWT) + assert.Equal(t, resp.Credentials[1].Credential.Issuer, issuerDID.DID.ID) + assert.Equal(t, "did:abc:789", resp.Credentials[1].Credential.CredentialSubject.GetID()) + assert.Equal(t, "Lemony", resp.Credentials[1].Credential.CredentialSubject["firstName"]) + assert.Equal(t, "Snickets", resp.Credentials[1].Credential.CredentialSubject["lastName"]) + assert.NotEmpty(t, resp.Credentials[1].Credential.CredentialStatus) }) - ttt.Run("Fails with malformed request", func(ttt *testing.T) { + t.Run("Fails with malformed request", func(t *testing.T) { batchCreateCredentialsRequest := batchCreateCredentialsRequest // missing the data field batchCreateCredentialsRequest.Requests = append(batchCreateCredentialsRequest.Requests, router.CreateCredentialRequest{ @@ -299,47 +299,47 @@ func TestCredentialAPI(t *testing.T) { Expiry: time.Now().Add(24 * time.Hour).Format(time.RFC3339), }) - requestValue := newRequestValue(ttt, batchCreateCredentialsRequest) + requestValue := newRequestValue(t, batchCreateCredentialsRequest) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/credentials/batch", requestValue) w := httptest.NewRecorder() c := newRequestContext(w, req) credRouter.BatchCreateCredentials(c) - assert.Equal(ttt, http.StatusBadRequest, w.Code) - assert.Contains(ttt, w.Body.String(), "invalid batch create credential request") + assert.Equal(t, http.StatusBadRequest, w.Code) + assert.Contains(t, w.Body.String(), "invalid batch create credential request") }) - ttt.Run("Fails with more than 1000 requests", func(ttt *testing.T) { + t.Run("Fails with more than 1000 requests", func(t *testing.T) { batchCreateCredentialsRequest := batchCreateCredentialsRequest // missing the data field for i := 0; i < 1000; i++ { batchCreateCredentialsRequest.Requests = append(batchCreateCredentialsRequest.Requests, batchCreateCredentialsRequest.Requests[0]) } - requestValue := newRequestValue(ttt, batchCreateCredentialsRequest) + requestValue := newRequestValue(t, batchCreateCredentialsRequest) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/credentials/batch", requestValue) w := httptest.NewRecorder() c := newRequestContext(w, req) credRouter.BatchCreateCredentials(c) - assert.Equal(ttt, http.StatusBadRequest, w.Code) - assert.Contains(ttt, w.Body.String(), "max number of requests is 1000") + assert.Equal(t, http.StatusBadRequest, w.Code) + assert.Contains(t, w.Body.String(), "max number of requests is 1000") }) }) - tt.Run("Test Create Credential", func(ttt *testing.T) { - db := test.ServiceStorage(ttt) - require.NotEmpty(ttt, db) + t.Run("Test Create Credential", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - keyStoreService, _ := testKeyStoreService(ttt, db) - didService, _ := testDIDService(ttt, db, keyStoreService, nil) - schemaService := testSchemaService(ttt, db, keyStoreService, didService) - credRouter := testCredentialRouter(ttt, db, keyStoreService, didService, schemaService) + keyStoreService, _ := testKeyStoreService(t, db) + didService, _ := testDIDService(t, db, keyStoreService, nil) + schemaService := testSchemaService(t, db, keyStoreService, didService) + credRouter := testCredentialRouter(t, db, keyStoreService, didService, schemaService) issuerDID, err := didService.CreateDIDByMethod(context.Background(), did.CreateDIDRequest{ Method: didsdk.KeyMethod, KeyType: crypto.Ed25519, }) - assert.NoError(ttt, err) - assert.NotEmpty(ttt, issuerDID) + assert.NoError(t, err) + assert.NotEmpty(t, issuerDID) // missing required field: data badCredRequest := router.CreateCredentialRequest{ @@ -348,13 +348,13 @@ func TestCredentialAPI(t *testing.T) { Subject: "did:abc:456", Expiry: time.Now().Add(24 * time.Hour).Format(time.RFC3339), } - badRequestValue := newRequestValue(ttt, badCredRequest) + badRequestValue := newRequestValue(t, badCredRequest) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/credentials", badRequestValue) w := httptest.NewRecorder() c := newRequestContext(w, req) credRouter.CreateCredential(c) - assert.Contains(ttt, w.Body.String(), "invalid create credential request") + assert.Contains(t, w.Body.String(), "invalid create credential request") // reset the http recorder w = httptest.NewRecorder() @@ -370,11 +370,11 @@ func TestCredentialAPI(t *testing.T) { }, Expiry: time.Now().Add(24 * time.Hour).Format(time.RFC3339), } - missingIssuerRequestValue := newRequestValue(ttt, missingIssuerRequest) + missingIssuerRequestValue := newRequestValue(t, missingIssuerRequest) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/credentials", missingIssuerRequestValue) c = newRequestContext(w, req) credRouter.CreateCredential(c) - assert.Contains(ttt, w.Body.String(), "getting key for signing credential") + assert.Contains(t, w.Body.String(), "getting key for signing credential") // reset the http recorder w = httptest.NewRecorder() @@ -390,41 +390,41 @@ func TestCredentialAPI(t *testing.T) { }, Expiry: time.Now().Add(24 * time.Hour).Format(time.RFC3339), } - requestValue := newRequestValue(ttt, createCredRequest) + requestValue := newRequestValue(t, createCredRequest) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/credentials", requestValue) c = newRequestContext(w, req) credRouter.CreateCredential(c) - assert.True(ttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.CreateCredentialResponse err = json.NewDecoder(w.Body).Decode(&resp) - assert.NoError(ttt, err) + assert.NoError(t, err) - assert.NotEmpty(ttt, resp.CredentialJWT) - assert.NoError(ttt, err) - assert.Equal(ttt, resp.Credential.Issuer, issuerDID.DID.ID) + assert.NotEmpty(t, resp.CredentialJWT) + assert.NoError(t, err) + assert.Equal(t, resp.Credential.Issuer, issuerDID.DID.ID) after, found := strings.CutPrefix(resp.Credential.ID, "https://ssi-service.com/v1/credentials/") - assert.True(ttt, found) - assert.NotPanics(ttt, func() { + assert.True(t, found) + assert.NotPanics(t, func() { uuid.MustParse(after) }) }) - tt.Run("Test Create Credential with Schema", func(ttt *testing.T) { - db := test.ServiceStorage(ttt) - require.NotEmpty(ttt, db) + t.Run("Test Create Credential with Schema", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - keyStoreService, _ := testKeyStoreService(ttt, db) - didService, _ := testDIDService(ttt, db, keyStoreService, nil) - schemaService := testSchemaService(ttt, db, keyStoreService, didService) - credRouter := testCredentialRouter(ttt, db, keyStoreService, didService, schemaService) + keyStoreService, _ := testKeyStoreService(t, db) + didService, _ := testDIDService(t, db, keyStoreService, nil) + schemaService := testSchemaService(t, db, keyStoreService, didService) + credRouter := testCredentialRouter(t, db, keyStoreService, didService, schemaService) issuerDID, err := didService.CreateDIDByMethod(context.Background(), did.CreateDIDRequest{ Method: didsdk.KeyMethod, KeyType: crypto.Ed25519, }) - assert.NoError(ttt, err) - assert.NotEmpty(ttt, issuerDID) + assert.NoError(t, err) + assert.NotEmpty(t, issuerDID) // create a schema simpleSchema := map[string]any{ @@ -449,8 +449,8 @@ func TestCredentialAPI(t *testing.T) { }, } createdSchema, err := schemaService.CreateSchema(context.Background(), schema.CreateSchemaRequest{Issuer: "me", Name: "simple schema", Schema: simpleSchema}) - assert.NoError(ttt, err) - assert.NotEmpty(ttt, createdSchema) + assert.NoError(t, err) + assert.NotEmpty(t, createdSchema) w := httptest.NewRecorder() @@ -465,16 +465,16 @@ func TestCredentialAPI(t *testing.T) { }, Expiry: time.Now().Add(24 * time.Hour).Format(time.RFC3339), } - requestValue := newRequestValue(ttt, createCredRequest) + requestValue := newRequestValue(t, createCredRequest) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/credentials", requestValue) c := newRequestContext(w, req) credRouter.CreateCredential(c) - assert.True(ttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.CreateCredentialResponse err = json.NewDecoder(w.Body).Decode(&resp) - assert.NoError(ttt, err) - assert.NotEmpty(ttt, resp.CredentialJWT) + assert.NoError(t, err) + assert.NotEmpty(t, resp.CredentialJWT) // reset the http recorder w = httptest.NewRecorder() @@ -483,17 +483,17 @@ func TestCredentialAPI(t *testing.T) { req = httptest.NewRequest(http.MethodGet, fmt.Sprintf("https://ssi-service.com/v1/credential?schema=%s", createdSchema.ID), nil) c = newRequestContextWithParams(w, req, map[string]string{"schema": createdSchema.ID}) credRouter.ListCredentials(c) - assert.True(ttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var getCredsResp router.ListCredentialsResponse err = json.NewDecoder(w.Body).Decode(&getCredsResp) - assert.NoError(ttt, err) - assert.NotEmpty(ttt, getCredsResp) - assert.Len(ttt, getCredsResp.Credentials, 1) + assert.NoError(t, err) + assert.NotEmpty(t, getCredsResp) + assert.Len(t, getCredsResp.Credentials, 1) - assert.Equal(ttt, resp.ID, getCredsResp.Credentials[0].ID) - assert.Equal(ttt, resp.Credential.ID, getCredsResp.Credentials[0].Credential.ID) - assert.Equal(ttt, resp.Credential.CredentialSchema.ID, getCredsResp.Credentials[0].Credential.CredentialSchema.ID) + assert.Equal(t, resp.ID, getCredsResp.Credentials[0].ID) + assert.Equal(t, resp.Credential.ID, getCredsResp.Credentials[0].Credential.ID) + assert.Equal(t, resp.Credential.CredentialSchema.ID, getCredsResp.Credentials[0].Credential.CredentialSchema.ID) // reset the http recorder w = httptest.NewRecorder() @@ -510,21 +510,21 @@ func TestCredentialAPI(t *testing.T) { }, Expiry: time.Now().Add(24 * time.Hour).Format(time.RFC3339), } - requestValue = newRequestValue(ttt, missingSchemaCred) + requestValue = newRequestValue(t, missingSchemaCred) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/credentials", requestValue) c = newRequestContext(w, req) credRouter.CreateCredential(c) - assert.Contains(ttt, w.Body.String(), "schema not found") + assert.Contains(t, w.Body.String(), "schema not found") }) - tt.Run("Test Get Credential By ID", func(ttt *testing.T) { - db := test.ServiceStorage(ttt) - require.NotEmpty(ttt, db) + t.Run("Test Get Credential By ID", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - keyStoreService, _ := testKeyStoreService(ttt, db) - didService, _ := testDIDService(ttt, db, keyStoreService, nil) - schemaService := testSchemaService(ttt, db, keyStoreService, didService) - credRouter := testCredentialRouter(ttt, db, keyStoreService, didService, schemaService) + keyStoreService, _ := testKeyStoreService(t, db) + didService, _ := testDIDService(t, db, keyStoreService, nil) + schemaService := testSchemaService(t, db, keyStoreService, didService) + credRouter := testCredentialRouter(t, db, keyStoreService, didService, schemaService) w := httptest.NewRecorder() @@ -532,7 +532,7 @@ func TestCredentialAPI(t *testing.T) { req := httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/credentials/bad", nil) c := newRequestContext(w, req) credRouter.GetCredential(c) - assert.Contains(ttt, w.Body.String(), "cannot get credential without ID parameter") + assert.Contains(t, w.Body.String(), "cannot get credential without ID parameter") // reset the http recorder w = httptest.NewRecorder() @@ -541,7 +541,7 @@ func TestCredentialAPI(t *testing.T) { req = httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/credentials/bad", nil) c = newRequestContextWithParams(w, req, map[string]string{"id": "bad"}) credRouter.GetCredential(c) - assert.Contains(ttt, w.Body.String(), "could not get credential with id: bad") + assert.Contains(t, w.Body.String(), "could not get credential with id: bad") // reset the http recorder w = httptest.NewRecorder() @@ -550,8 +550,8 @@ func TestCredentialAPI(t *testing.T) { Method: didsdk.KeyMethod, KeyType: crypto.Ed25519, }) - assert.NoError(ttt, err) - assert.NotEmpty(ttt, issuerDID) + assert.NoError(t, err) + assert.NotEmpty(t, issuerDID) createCredRequest := router.CreateCredentialRequest{ Issuer: issuerDID.DID.ID, @@ -563,18 +563,18 @@ func TestCredentialAPI(t *testing.T) { }, Expiry: time.Now().Add(24 * time.Hour).Format(time.RFC3339), } - requestValue := newRequestValue(ttt, createCredRequest) + requestValue := newRequestValue(t, createCredRequest) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/credentials", requestValue) c = newRequestContext(w, req) credRouter.CreateCredential(c) - assert.True(ttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) // We expect a JWT credential var resp router.CreateCredentialResponse err = json.NewDecoder(w.Body).Decode(&resp) - assert.NoError(ttt, err) - assert.NotEmpty(ttt, resp.Credential) - assert.NotEmpty(ttt, resp.CredentialJWT) + assert.NoError(t, err) + assert.NotEmpty(t, resp.Credential) + assert.NotEmpty(t, resp.CredentialJWT) // reset the http recorder w = httptest.NewRecorder() @@ -583,24 +583,24 @@ func TestCredentialAPI(t *testing.T) { req = httptest.NewRequest(http.MethodGet, resp.Credential.ID, nil) c = newRequestContextWithParams(w, req, map[string]string{"id": idFromURI(resp.Credential.ID)}) credRouter.GetCredential(c) - assert.True(ttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var getCredResp router.GetCredentialResponse err = json.NewDecoder(w.Body).Decode(&getCredResp) - assert.NoError(ttt, err) - assert.NotEmpty(ttt, getCredResp) - assert.NotEmpty(ttt, getCredResp.CredentialJWT) - assert.Equal(ttt, resp.Credential.ID, getCredResp.Credential.ID) + assert.NoError(t, err) + assert.NotEmpty(t, getCredResp) + assert.NotEmpty(t, getCredResp.CredentialJWT) + assert.Equal(t, resp.Credential.ID, getCredResp.Credential.ID) }) - tt.Run("Test Get Credential By Schema", func(ttt *testing.T) { - db := test.ServiceStorage(ttt) - require.NotEmpty(ttt, db) + t.Run("Test Get Credential By Schema", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - keyStoreService, _ := testKeyStoreService(ttt, db) - didService, _ := testDIDService(ttt, db, keyStoreService, nil) - schemaService := testSchemaService(ttt, db, keyStoreService, didService) - credRouter := testCredentialRouter(ttt, db, keyStoreService, didService, schemaService) + keyStoreService, _ := testKeyStoreService(t, db) + didService, _ := testDIDService(t, db, keyStoreService, nil) + schemaService := testSchemaService(t, db, keyStoreService, didService) + credRouter := testCredentialRouter(t, db, keyStoreService, didService, schemaService) w := httptest.NewRecorder() @@ -608,8 +608,8 @@ func TestCredentialAPI(t *testing.T) { Method: didsdk.KeyMethod, KeyType: crypto.Ed25519, }) - assert.NoError(ttt, err) - assert.NotEmpty(ttt, issuerDID) + assert.NoError(t, err) + assert.NotEmpty(t, issuerDID) // create a schema simpleSchema := map[string]any{ @@ -634,8 +634,8 @@ func TestCredentialAPI(t *testing.T) { }, } createdSchema, err := schemaService.CreateSchema(context.Background(), schema.CreateSchemaRequest{Issuer: "me", Name: "simple schema", Schema: simpleSchema}) - assert.NoError(ttt, err) - assert.NotEmpty(ttt, createdSchema) + assert.NoError(t, err) + assert.NotEmpty(t, createdSchema) createCredRequest := router.CreateCredentialRequest{ Issuer: issuerDID.DID.ID, @@ -648,16 +648,16 @@ func TestCredentialAPI(t *testing.T) { }, Expiry: time.Now().Add(24 * time.Hour).Format(time.RFC3339), } - requestValue := newRequestValue(ttt, createCredRequest) + requestValue := newRequestValue(t, createCredRequest) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/credentials", requestValue) c := newRequestContext(w, req) credRouter.CreateCredential(c) - assert.True(ttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.CreateCredentialResponse err = json.NewDecoder(w.Body).Decode(&resp) - assert.NoError(ttt, err) - assert.NotEmpty(ttt, resp.CredentialJWT) + assert.NoError(t, err) + assert.NotEmpty(t, resp.CredentialJWT) // reset the http recorder w = httptest.NewRecorder() @@ -666,27 +666,27 @@ func TestCredentialAPI(t *testing.T) { req = httptest.NewRequest(http.MethodGet, fmt.Sprintf("https://ssi-service.com/v1/credential?schema=%s", createdSchema.ID), nil) c = newRequestContext(w, req) credRouter.ListCredentials(c) - assert.True(ttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var getCredsResp router.ListCredentialsResponse err = json.NewDecoder(w.Body).Decode(&getCredsResp) - assert.NoError(ttt, err) - assert.NotEmpty(ttt, getCredsResp) - assert.Len(ttt, getCredsResp.Credentials, 1) + assert.NoError(t, err) + assert.NotEmpty(t, getCredsResp) + assert.Len(t, getCredsResp.Credentials, 1) - assert.Equal(ttt, resp.ID, getCredsResp.Credentials[0].ID) - assert.Equal(ttt, resp.Credential.ID, getCredsResp.Credentials[0].Credential.ID) - assert.Equal(ttt, resp.Credential.CredentialSchema.ID, getCredsResp.Credentials[0].Credential.CredentialSchema.ID) + assert.Equal(t, resp.ID, getCredsResp.Credentials[0].ID) + assert.Equal(t, resp.Credential.ID, getCredsResp.Credentials[0].Credential.ID) + assert.Equal(t, resp.Credential.CredentialSchema.ID, getCredsResp.Credentials[0].Credential.CredentialSchema.ID) }) - tt.Run("Get Credential No Param", func(ttt *testing.T) { - db := test.ServiceStorage(ttt) - require.NotEmpty(ttt, db) + t.Run("Get Credential No Param", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - keyStoreService, _ := testKeyStoreService(ttt, db) - didService, _ := testDIDService(ttt, db, keyStoreService, nil) - schemaService := testSchemaService(ttt, db, keyStoreService, didService) - credRouter := testCredentialRouter(ttt, db, keyStoreService, didService, schemaService) + keyStoreService, _ := testKeyStoreService(t, db) + didService, _ := testDIDService(t, db, keyStoreService, nil) + schemaService := testSchemaService(t, db, keyStoreService, didService) + credRouter := testCredentialRouter(t, db, keyStoreService, didService, schemaService) w := httptest.NewRecorder() @@ -694,8 +694,8 @@ func TestCredentialAPI(t *testing.T) { Method: didsdk.KeyMethod, KeyType: crypto.Ed25519, }) - assert.NoError(ttt, err) - assert.NotEmpty(ttt, issuerDID) + assert.NoError(t, err) + assert.NotEmpty(t, issuerDID) createCredRequest := router.CreateCredentialRequest{ Issuer: issuerDID.DID.ID, @@ -707,16 +707,16 @@ func TestCredentialAPI(t *testing.T) { }, Expiry: time.Now().Add(24 * time.Hour).Format(time.RFC3339), } - requestValue := newRequestValue(ttt, createCredRequest) + requestValue := newRequestValue(t, createCredRequest) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/credentials", requestValue) c := newRequestContext(w, req) credRouter.CreateCredential(c) - assert.True(ttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.CreateCredentialResponse err = json.NewDecoder(w.Body).Decode(&resp) - assert.NoError(ttt, err) - assert.NotEmpty(ttt, resp.CredentialJWT) + assert.NoError(t, err) + assert.NotEmpty(t, resp.CredentialJWT) // reset the http recorder w = httptest.NewRecorder() @@ -725,26 +725,26 @@ func TestCredentialAPI(t *testing.T) { req = httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/credentials", nil) c = newRequestContext(w, req) credRouter.ListCredentials(c) - assert.True(ttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var getCredsResp router.ListCredentialsResponse err = json.NewDecoder(w.Body).Decode(&getCredsResp) - assert.NoError(ttt, err) - assert.NotEmpty(ttt, getCredsResp) + assert.NoError(t, err) + assert.NotEmpty(t, getCredsResp) - assert.Len(ttt, getCredsResp.Credentials, 1) - assert.Equal(ttt, resp.ID, getCredsResp.Credentials[0].ID) - assert.Equal(ttt, resp.Credential.ID, getCredsResp.Credentials[0].Credential.ID) + assert.Len(t, getCredsResp.Credentials, 1) + assert.Equal(t, resp.ID, getCredsResp.Credentials[0].ID) + assert.Equal(t, resp.Credential.ID, getCredsResp.Credentials[0].Credential.ID) }) - tt.Run("Test Get Credential By Issuer", func(ttt *testing.T) { - db := test.ServiceStorage(ttt) - require.NotEmpty(ttt, db) + t.Run("Test Get Credential By Issuer", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - keyStoreService, _ := testKeyStoreService(ttt, db) - didService, _ := testDIDService(ttt, db, keyStoreService, nil) - schemaService := testSchemaService(ttt, db, keyStoreService, didService) - credRouter := testCredentialRouter(ttt, db, keyStoreService, didService, schemaService) + keyStoreService, _ := testKeyStoreService(t, db) + didService, _ := testDIDService(t, db, keyStoreService, nil) + schemaService := testSchemaService(t, db, keyStoreService, didService) + credRouter := testCredentialRouter(t, db, keyStoreService, didService, schemaService) w := httptest.NewRecorder() @@ -752,8 +752,8 @@ func TestCredentialAPI(t *testing.T) { Method: didsdk.KeyMethod, KeyType: crypto.Ed25519, }) - assert.NoError(ttt, err) - assert.NotEmpty(ttt, issuerDID) + assert.NoError(t, err) + assert.NotEmpty(t, issuerDID) createCredRequest := router.CreateCredentialRequest{ Issuer: issuerDID.DID.ID, @@ -765,16 +765,16 @@ func TestCredentialAPI(t *testing.T) { }, Expiry: time.Now().Add(24 * time.Hour).Format(time.RFC3339), } - requestValue := newRequestValue(ttt, createCredRequest) + requestValue := newRequestValue(t, createCredRequest) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/credentials", requestValue) c := newRequestContext(w, req) credRouter.CreateCredential(c) - assert.True(ttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.CreateCredentialResponse err = json.NewDecoder(w.Body).Decode(&resp) - assert.NoError(ttt, err) - assert.NotEmpty(ttt, resp.CredentialJWT) + assert.NoError(t, err) + assert.NotEmpty(t, resp.CredentialJWT) // reset the http recorder w = httptest.NewRecorder() @@ -783,26 +783,26 @@ func TestCredentialAPI(t *testing.T) { req = httptest.NewRequest(http.MethodGet, fmt.Sprintf("https://ssi-service.com/v1/credential?issuer=%s", issuerDID.DID.ID), nil) c = newRequestContext(w, req) credRouter.ListCredentials(c) - assert.True(ttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var getCredsResp router.ListCredentialsResponse err = json.NewDecoder(w.Body).Decode(&getCredsResp) - assert.NoError(ttt, err) - assert.NotEmpty(ttt, getCredsResp) + assert.NoError(t, err) + assert.NotEmpty(t, getCredsResp) - assert.Len(ttt, getCredsResp.Credentials, 1) - assert.Equal(ttt, resp.ID, getCredsResp.Credentials[0].ID) - assert.Equal(ttt, resp.Credential.ID, getCredsResp.Credentials[0].Credential.ID) + assert.Len(t, getCredsResp.Credentials, 1) + assert.Equal(t, resp.ID, getCredsResp.Credentials[0].ID) + assert.Equal(t, resp.Credential.ID, getCredsResp.Credentials[0].Credential.ID) }) - tt.Run("Test Get Credential By Subject", func(ttt *testing.T) { - db := test.ServiceStorage(ttt) - require.NotEmpty(ttt, db) + t.Run("Test Get Credential By Subject", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - keyStoreService, _ := testKeyStoreService(ttt, db) - didService, _ := testDIDService(ttt, db, keyStoreService, nil) - schemaService := testSchemaService(ttt, db, keyStoreService, didService) - credRouter := testCredentialRouter(ttt, db, keyStoreService, didService, schemaService) + keyStoreService, _ := testKeyStoreService(t, db) + didService, _ := testDIDService(t, db, keyStoreService, nil) + schemaService := testSchemaService(t, db, keyStoreService, didService) + credRouter := testCredentialRouter(t, db, keyStoreService, didService, schemaService) w := httptest.NewRecorder() @@ -810,8 +810,8 @@ func TestCredentialAPI(t *testing.T) { Method: didsdk.KeyMethod, KeyType: crypto.Ed25519, }) - assert.NoError(ttt, err) - assert.NotEmpty(ttt, issuerDID) + assert.NoError(t, err) + assert.NotEmpty(t, issuerDID) subjectID := "did:abc:456" createCredRequest := router.CreateCredentialRequest{ @@ -824,16 +824,16 @@ func TestCredentialAPI(t *testing.T) { }, Expiry: time.Now().Add(24 * time.Hour).Format(time.RFC3339), } - requestValue := newRequestValue(ttt, createCredRequest) + requestValue := newRequestValue(t, createCredRequest) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/credentials", requestValue) c := newRequestContext(w, req) credRouter.CreateCredential(c) - assert.True(ttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var createCredentialResponse router.CreateCredentialResponse err = json.NewDecoder(w.Body).Decode(&createCredentialResponse) - assert.NoError(ttt, err) - assert.NotEmpty(ttt, createCredentialResponse.CredentialJWT) + assert.NoError(t, err) + assert.NotEmpty(t, createCredentialResponse.CredentialJWT) // reset the http recorder w = httptest.NewRecorder() @@ -842,34 +842,34 @@ func TestCredentialAPI(t *testing.T) { req = httptest.NewRequest(http.MethodGet, fmt.Sprintf("https://ssi-service.com/v1/credential?subject=%s", subjectID), nil) c = newRequestContext(w, req) credRouter.ListCredentials(c) - assert.True(ttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var listCredentialsResponse router.ListCredentialsResponse err = json.NewDecoder(w.Body).Decode(&listCredentialsResponse) - assert.NoError(ttt, err) - assert.NotEmpty(ttt, listCredentialsResponse) + assert.NoError(t, err) + assert.NotEmpty(t, listCredentialsResponse) - assert.Len(ttt, listCredentialsResponse.Credentials, 1) - assert.Equal(ttt, createCredentialResponse.ID, listCredentialsResponse.Credentials[0].ID) - assert.Equal(ttt, createCredentialResponse.Credential.ID, listCredentialsResponse.Credentials[0].Credential.ID) - assert.Equal(ttt, createCredentialResponse.Credential.CredentialSubject[credsdk.VerifiableCredentialIDProperty], listCredentialsResponse.Credentials[0].Credential.CredentialSubject[credsdk.VerifiableCredentialIDProperty]) + assert.Len(t, listCredentialsResponse.Credentials, 1) + assert.Equal(t, createCredentialResponse.ID, listCredentialsResponse.Credentials[0].ID) + assert.Equal(t, createCredentialResponse.Credential.ID, listCredentialsResponse.Credentials[0].Credential.ID) + assert.Equal(t, createCredentialResponse.Credential.CredentialSubject[credsdk.VerifiableCredentialIDProperty], listCredentialsResponse.Credentials[0].Credential.CredentialSubject[credsdk.VerifiableCredentialIDProperty]) }) - tt.Run("Test Delete Credential", func(ttt *testing.T) { - db := test.ServiceStorage(ttt) - require.NotEmpty(ttt, db) + t.Run("Test Delete Credential", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - keyStoreService, _ := testKeyStoreService(ttt, db) - didService, _ := testDIDService(ttt, db, keyStoreService, nil) - schemaService := testSchemaService(ttt, db, keyStoreService, didService) - credRouter := testCredentialRouter(ttt, db, keyStoreService, didService, schemaService) + keyStoreService, _ := testKeyStoreService(t, db) + didService, _ := testDIDService(t, db, keyStoreService, nil) + schemaService := testSchemaService(t, db, keyStoreService, didService) + credRouter := testCredentialRouter(t, db, keyStoreService, didService, schemaService) issuerDID, err := didService.CreateDIDByMethod(context.Background(), did.CreateDIDRequest{ Method: didsdk.KeyMethod, KeyType: crypto.Ed25519, }) - assert.NoError(ttt, err) - assert.NotEmpty(ttt, issuerDID) + assert.NoError(t, err) + assert.NotEmpty(t, issuerDID) createCredRequest := router.CreateCredentialRequest{ Issuer: issuerDID.DID.ID, @@ -881,16 +881,16 @@ func TestCredentialAPI(t *testing.T) { }, Expiry: time.Now().Add(24 * time.Hour).Format(time.RFC3339), } - requestValue := newRequestValue(ttt, createCredRequest) + requestValue := newRequestValue(t, createCredRequest) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/credentials", requestValue) w := httptest.NewRecorder() c := newRequestContext(w, req) credRouter.CreateCredential(c) - assert.True(ttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.CreateCredentialResponse err = json.NewDecoder(w.Body).Decode(&resp) - assert.NoError(ttt, err) + assert.NoError(t, err) // reset the http recorder w = httptest.NewRecorder() @@ -900,13 +900,13 @@ func TestCredentialAPI(t *testing.T) { req = httptest.NewRequest(http.MethodGet, credID, nil) c = newRequestContextWithParams(w, req, map[string]string{"id": idFromURI(credID)}) credRouter.GetCredential(c) - assert.True(ttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var getCredResp router.GetCredentialResponse err = json.NewDecoder(w.Body).Decode(&getCredResp) - assert.NoError(ttt, err) - assert.NotEmpty(ttt, getCredResp) - assert.Equal(ttt, credID, getCredResp.Credential.ID) + assert.NoError(t, err) + assert.NotEmpty(t, getCredResp) + assert.Equal(t, credID, getCredResp.Credential.ID) // reset the http recorder w = httptest.NewRecorder() @@ -915,7 +915,7 @@ func TestCredentialAPI(t *testing.T) { req = httptest.NewRequest(http.MethodDelete, fmt.Sprintf("https://ssi-service.com/v1/credentials/%s", credID), nil) c = newRequestContextWithParams(w, req, map[string]string{"id": credID}) credRouter.DeleteCredential(c) - assert.True(ttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) // reset the http recorder w = httptest.NewRecorder() @@ -924,24 +924,24 @@ func TestCredentialAPI(t *testing.T) { req = httptest.NewRequest(http.MethodGet, fmt.Sprintf("https://ssi-service.com/v1/credentials/%s", credID), nil) c = newRequestContextWithParams(w, req, map[string]string{"id": credID}) credRouter.GetCredential(c) - assert.Contains(ttt, w.Body.String(), fmt.Sprintf("could not get credential with id: %s", credID)) + assert.Contains(t, w.Body.String(), fmt.Sprintf("could not get credential with id: %s", credID)) }) - tt.Run("Test Verifying a Credential", func(ttt *testing.T) { - db := test.ServiceStorage(ttt) - require.NotEmpty(ttt, db) + t.Run("Test Verifying a Credential", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - keyStoreService, _ := testKeyStoreService(ttt, db) - didService, _ := testDIDService(ttt, db, keyStoreService, nil) - schemaService := testSchemaService(ttt, db, keyStoreService, didService) - credRouter := testCredentialRouter(ttt, db, keyStoreService, didService, schemaService) + keyStoreService, _ := testKeyStoreService(t, db) + didService, _ := testDIDService(t, db, keyStoreService, nil) + schemaService := testSchemaService(t, db, keyStoreService, didService) + credRouter := testCredentialRouter(t, db, keyStoreService, didService, schemaService) issuerDID, err := didService.CreateDIDByMethod(context.Background(), did.CreateDIDRequest{ Method: didsdk.KeyMethod, KeyType: crypto.Ed25519, }) - assert.NoError(ttt, err) - assert.NotEmpty(ttt, issuerDID) + assert.NoError(t, err) + assert.NotEmpty(t, issuerDID) // good request createCredRequest := router.CreateCredentialRequest{ @@ -954,73 +954,73 @@ func TestCredentialAPI(t *testing.T) { }, Expiry: time.Now().Add(24 * time.Hour).Format(time.RFC3339), } - requestValue := newRequestValue(ttt, createCredRequest) + requestValue := newRequestValue(t, createCredRequest) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/credentials", requestValue) w := httptest.NewRecorder() c := newRequestContext(w, req) credRouter.CreateCredential(c) - assert.True(ttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.CreateCredentialResponse err = json.NewDecoder(w.Body).Decode(&resp) - assert.NoError(ttt, err) + assert.NoError(t, err) - assert.NotEmpty(ttt, resp.CredentialJWT) - assert.NoError(ttt, err) - assert.Equal(ttt, resp.Credential.Issuer, issuerDID.DID.ID) + assert.NotEmpty(t, resp.CredentialJWT) + assert.NoError(t, err) + assert.Equal(t, resp.Credential.Issuer, issuerDID.DID.ID) // reset the http recorder w = httptest.NewRecorder() // verify the credential - requestValue = newRequestValue(ttt, router.VerifyCredentialRequest{CredentialJWT: resp.CredentialJWT}) + requestValue = newRequestValue(t, router.VerifyCredentialRequest{CredentialJWT: resp.CredentialJWT}) req = httptest.NewRequest(http.MethodPost, "https://ssi-service.com/v1/credentials/verification", requestValue) c = newRequestContext(w, req) credRouter.VerifyCredential(c) - assert.True(ttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var verifyResp router.VerifyCredentialResponse err = json.NewDecoder(w.Body).Decode(&verifyResp) - assert.NoError(ttt, err) - assert.NotEmpty(ttt, verifyResp) - assert.True(ttt, verifyResp.Verified) + assert.NoError(t, err) + assert.NotEmpty(t, verifyResp) + assert.True(t, verifyResp.Verified) // bad credential - requestValue = newRequestValue(ttt, router.VerifyCredentialRequest{CredentialJWT: keyaccess.JWTPtr("bad")}) + requestValue = newRequestValue(t, router.VerifyCredentialRequest{CredentialJWT: keyaccess.JWTPtr("bad")}) req = httptest.NewRequest(http.MethodPost, "https://ssi-service.com/v1/credentials/verification", requestValue) c = newRequestContext(w, req) credRouter.VerifyCredential(c) - assert.True(ttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) err = json.NewDecoder(w.Body).Decode(&verifyResp) - assert.NoError(ttt, err) - assert.NotEmpty(ttt, verifyResp) - assert.False(ttt, verifyResp.Verified) - assert.Contains(ttt, verifyResp.Reason, "parsing JWT: parsing credential token: invalid JWT") + assert.NoError(t, err) + assert.NotEmpty(t, verifyResp) + assert.False(t, verifyResp.Verified) + assert.Contains(t, verifyResp.Reason, "parsing JWT: parsing credential token: invalid JWT") }) - tt.Run("Test Create Revocable Credential", func(ttt *testing.T) { - db := test.ServiceStorage(ttt) - require.NotEmpty(ttt, db) + t.Run("Test Create Revocable Credential", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - keyStoreService, _ := testKeyStoreService(ttt, db) - didService, _ := testDIDService(ttt, db, keyStoreService, nil) - schemaService := testSchemaService(ttt, db, keyStoreService, didService) - credRouter := testCredentialRouter(ttt, db, keyStoreService, didService, schemaService) + keyStoreService, _ := testKeyStoreService(t, db) + didService, _ := testDIDService(t, db, keyStoreService, nil) + schemaService := testSchemaService(t, db, keyStoreService, didService) + credRouter := testCredentialRouter(t, db, keyStoreService, didService, schemaService) issuerDID, err := didService.CreateDIDByMethod(context.Background(), did.CreateDIDRequest{ Method: didsdk.KeyMethod, KeyType: crypto.Ed25519, }) - assert.NoError(ttt, err) - assert.NotEmpty(ttt, issuerDID) + assert.NoError(t, err) + assert.NotEmpty(t, issuerDID) issuerDIDTwo, err := didService.CreateDIDByMethod(context.Background(), did.CreateDIDRequest{ Method: didsdk.KeyMethod, KeyType: crypto.Ed25519, }) - assert.NoError(ttt, err) - assert.NotEmpty(ttt, issuerDIDTwo) + assert.NoError(t, err) + assert.NotEmpty(t, issuerDIDTwo) w := httptest.NewRecorder() @@ -1035,20 +1035,20 @@ func TestCredentialAPI(t *testing.T) { }, Expiry: time.Now().Add(24 * time.Hour).Format(time.RFC3339), } - requestValue := newRequestValue(ttt, createCredRequest) + requestValue := newRequestValue(t, createCredRequest) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/credentials", requestValue) c := newRequestContext(w, req) credRouter.CreateCredential(c) - assert.True(ttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.CreateCredentialResponse err = json.NewDecoder(w.Body).Decode(&resp) - assert.NoError(ttt, err) + assert.NoError(t, err) - assert.NotEmpty(ttt, resp.CredentialJWT) - assert.NoError(ttt, err) - assert.Empty(ttt, resp.Credential.CredentialStatus) - assert.Equal(ttt, resp.Credential.Issuer, issuerDID.DID.ID) + assert.NotEmpty(t, resp.CredentialJWT) + assert.NoError(t, err) + assert.Empty(t, resp.Credential.CredentialStatus) + assert.Equal(t, resp.Credential.Issuer, issuerDID.DID.ID) // good revocable request One createRevocableCredRequestOne := router.CreateCredentialRequest{ @@ -1063,24 +1063,24 @@ func TestCredentialAPI(t *testing.T) { Revocable: true, } - requestValue = newRequestValue(ttt, createRevocableCredRequestOne) + requestValue = newRequestValue(t, createRevocableCredRequestOne) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/credentials", requestValue) c = newRequestContext(w, req) credRouter.CreateCredential(c) - assert.True(ttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var revocableRespOne router.CreateCredentialResponse err = json.NewDecoder(w.Body).Decode(&revocableRespOne) - assert.NoError(ttt, err) + assert.NoError(t, err) - assert.NotEmpty(ttt, revocableRespOne.CredentialJWT) - assert.NotEmpty(ttt, revocableRespOne.Credential.CredentialStatus) - assert.Equal(ttt, revocableRespOne.Credential.Issuer, issuerDID.DID.ID) + assert.NotEmpty(t, revocableRespOne.CredentialJWT) + assert.NotEmpty(t, revocableRespOne.Credential.CredentialStatus) + assert.Equal(t, revocableRespOne.Credential.Issuer, issuerDID.DID.ID) credStatusMap, ok := revocableRespOne.Credential.CredentialStatus.(map[string]any) - assert.True(ttt, ok) + assert.True(t, ok) - assert.NotEmpty(ttt, credStatusMap["statusListIndex"]) + assert.NotEmpty(t, credStatusMap["statusListIndex"]) // good revocable request Two createRevocableCredRequestTwo := router.CreateCredentialRequest{ @@ -1095,24 +1095,24 @@ func TestCredentialAPI(t *testing.T) { Revocable: true, } - requestValue = newRequestValue(ttt, createRevocableCredRequestTwo) + requestValue = newRequestValue(t, createRevocableCredRequestTwo) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/credentials", requestValue) c = newRequestContext(w, req) credRouter.CreateCredential(c) - assert.True(ttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var revocableRespTwo router.CreateCredentialResponse err = json.NewDecoder(w.Body).Decode(&revocableRespTwo) - assert.NoError(ttt, err) + assert.NoError(t, err) - assert.NotEmpty(ttt, revocableRespTwo.CredentialJWT) - assert.NotEmpty(ttt, revocableRespTwo.Credential.CredentialStatus) - assert.Equal(ttt, revocableRespTwo.Credential.Issuer, issuerDID.DID.ID) + assert.NotEmpty(t, revocableRespTwo.CredentialJWT) + assert.NotEmpty(t, revocableRespTwo.Credential.CredentialStatus) + assert.Equal(t, revocableRespTwo.Credential.Issuer, issuerDID.DID.ID) credStatusMap, ok = revocableRespTwo.Credential.CredentialStatus.(map[string]any) - assert.True(ttt, ok) + assert.True(t, ok) - assert.NotEmpty(ttt, credStatusMap["statusListIndex"]) + assert.NotEmpty(t, credStatusMap["statusListIndex"]) // good revocable request Three createRevocableCredRequestThree := router.CreateCredentialRequest{ @@ -1127,24 +1127,24 @@ func TestCredentialAPI(t *testing.T) { Revocable: true, } - requestValue = newRequestValue(ttt, createRevocableCredRequestThree) + requestValue = newRequestValue(t, createRevocableCredRequestThree) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/credentials", requestValue) c = newRequestContext(w, req) credRouter.CreateCredential(c) - assert.True(ttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var revocableRespThree router.CreateCredentialResponse err = json.NewDecoder(w.Body).Decode(&revocableRespThree) - assert.NoError(ttt, err) + assert.NoError(t, err) - assert.NotEmpty(ttt, revocableRespThree.CredentialJWT) - assert.NotEmpty(ttt, revocableRespThree.Credential.CredentialStatus) - assert.Equal(ttt, revocableRespThree.Credential.Issuer, issuerDID.DID.ID) + assert.NotEmpty(t, revocableRespThree.CredentialJWT) + assert.NotEmpty(t, revocableRespThree.Credential.CredentialStatus) + assert.Equal(t, revocableRespThree.Credential.Issuer, issuerDID.DID.ID) credStatusMap, ok = revocableRespThree.Credential.CredentialStatus.(map[string]any) - assert.True(ttt, ok) + assert.True(t, ok) - assert.NotEmpty(ttt, credStatusMap["statusListIndex"]) + assert.NotEmpty(t, credStatusMap["statusListIndex"]) // good revocable request Four (different issuer / schema) createRevocableCredRequestFour := router.CreateCredentialRequest{ @@ -1159,41 +1159,41 @@ func TestCredentialAPI(t *testing.T) { Revocable: true, } - requestValue = newRequestValue(ttt, createRevocableCredRequestFour) + requestValue = newRequestValue(t, createRevocableCredRequestFour) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/credentials", requestValue) c = newRequestContext(w, req) credRouter.CreateCredential(c) - assert.True(ttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var revocableRespFour router.CreateCredentialResponse err = json.NewDecoder(w.Body).Decode(&revocableRespFour) - assert.NoError(ttt, err) + assert.NoError(t, err) - assert.NotEmpty(ttt, revocableRespFour.CredentialJWT) - assert.NotEmpty(ttt, revocableRespFour.Credential.CredentialStatus) - assert.Equal(ttt, revocableRespFour.Credential.Issuer, issuerDIDTwo.DID.ID) + assert.NotEmpty(t, revocableRespFour.CredentialJWT) + assert.NotEmpty(t, revocableRespFour.Credential.CredentialStatus) + assert.Equal(t, revocableRespFour.Credential.Issuer, issuerDIDTwo.DID.ID) credStatusMap, ok = revocableRespFour.Credential.CredentialStatus.(map[string]any) - assert.True(ttt, ok) + assert.True(t, ok) - assert.NotEmpty(ttt, credStatusMap["statusListIndex"]) + assert.NotEmpty(t, credStatusMap["statusListIndex"]) }) - tt.Run("Test Get Revoked Status Of Credential", func(ttt *testing.T) { - db := test.ServiceStorage(ttt) - require.NotEmpty(ttt, db) + t.Run("Test Get Revoked Status Of Credential", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - keyStoreService, _ := testKeyStoreService(ttt, db) - didService, _ := testDIDService(ttt, db, keyStoreService, nil) - schemaService := testSchemaService(ttt, db, keyStoreService, didService) - credRouter := testCredentialRouter(ttt, db, keyStoreService, didService, schemaService) + keyStoreService, _ := testKeyStoreService(t, db) + didService, _ := testDIDService(t, db, keyStoreService, nil) + schemaService := testSchemaService(t, db, keyStoreService, didService) + credRouter := testCredentialRouter(t, db, keyStoreService, didService, schemaService) issuerDID, err := didService.CreateDIDByMethod(context.Background(), did.CreateDIDRequest{ Method: didsdk.KeyMethod, KeyType: crypto.Ed25519, }) - assert.NoError(ttt, err) - assert.NotEmpty(ttt, issuerDID) + assert.NoError(t, err) + assert.NotEmpty(t, issuerDID) w := httptest.NewRecorder() @@ -1210,66 +1210,66 @@ func TestCredentialAPI(t *testing.T) { Revocable: true, } - requestValue := newRequestValue(ttt, createCredRequest) + requestValue := newRequestValue(t, createCredRequest) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/credentials", requestValue) c := newRequestContext(w, req) credRouter.CreateCredential(c) - assert.True(ttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.CreateCredentialResponse err = json.NewDecoder(w.Body).Decode(&resp) - assert.NoError(ttt, err) + assert.NoError(t, err) - assert.NotEmpty(ttt, resp.CredentialJWT) - assert.NotEmpty(ttt, resp.Credential.CredentialStatus) - assert.Equal(ttt, resp.Credential.Issuer, issuerDID.DID.ID) + assert.NotEmpty(t, resp.CredentialJWT) + assert.NotEmpty(t, resp.Credential.CredentialStatus) + assert.Equal(t, resp.Credential.Issuer, issuerDID.DID.ID) credStatusMap, ok := resp.Credential.CredentialStatus.(map[string]any) - assert.True(ttt, ok) + assert.True(t, ok) - assert.NotEmpty(ttt, credStatusMap["statusListIndex"]) + assert.NotEmpty(t, credStatusMap["statusListIndex"]) req = httptest.NewRequest(http.MethodGet, fmt.Sprintf("%s/status", resp.Credential.ID), nil) c = newRequestContextWithParams(w, req, map[string]string{"id": idFromURI(resp.Credential.ID)}) credRouter.GetCredentialStatus(c) - assert.True(ttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var credStatusResponse = router.GetCredentialStatusResponse{} err = json.NewDecoder(w.Body).Decode(&credStatusResponse) - assert.NoError(ttt, err) - assert.Equal(ttt, false, credStatusResponse.Revoked) + assert.NoError(t, err) + assert.Equal(t, false, credStatusResponse.Revoked) // good request number one updateCredStatusRequest := router.UpdateCredentialStatusRequest{Revoked: true} - requestValue = newRequestValue(ttt, updateCredStatusRequest) + requestValue = newRequestValue(t, updateCredStatusRequest) req = httptest.NewRequest(http.MethodPut, fmt.Sprintf("%s/status", resp.Credential.ID), requestValue) c = newRequestContextWithParams(w, req, map[string]string{"id": idFromURI(resp.Credential.ID)}) credRouter.UpdateCredentialStatus(c) - assert.True(ttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var credStatusUpdateResponse = router.UpdateCredentialStatusResponse{} err = json.NewDecoder(w.Body).Decode(&credStatusUpdateResponse) - assert.NoError(ttt, err) - assert.Equal(ttt, true, credStatusUpdateResponse.Revoked) + assert.NoError(t, err) + assert.Equal(t, true, credStatusUpdateResponse.Revoked) }) - tt.Run("Test Get Status List Credential", func(ttt *testing.T) { - db := test.ServiceStorage(ttt) - require.NotEmpty(ttt, db) + t.Run("Test Get Status List Credential", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - keyStoreService, _ := testKeyStoreService(ttt, db) - didService, _ := testDIDService(ttt, db, keyStoreService, nil) - schemaService := testSchemaService(ttt, db, keyStoreService, didService) - credRouter := testCredentialRouter(ttt, db, keyStoreService, didService, schemaService) + keyStoreService, _ := testKeyStoreService(t, db) + didService, _ := testDIDService(t, db, keyStoreService, nil) + schemaService := testSchemaService(t, db, keyStoreService, didService) + credRouter := testCredentialRouter(t, db, keyStoreService, didService, schemaService) issuerDID, err := didService.CreateDIDByMethod(context.Background(), did.CreateDIDRequest{ Method: didsdk.KeyMethod, KeyType: crypto.Ed25519, }) - assert.NoError(ttt, err) - assert.NotEmpty(ttt, issuerDID) + assert.NoError(t, err) + assert.NotEmpty(t, issuerDID) w := httptest.NewRecorder() @@ -1286,28 +1286,28 @@ func TestCredentialAPI(t *testing.T) { Revocable: true, } - requestValue := newRequestValue(ttt, createCredRequest) + requestValue := newRequestValue(t, createCredRequest) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/credentials", requestValue) c := newRequestContext(w, req) credRouter.CreateCredential(c) - assert.True(ttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.CreateCredentialResponse err = json.NewDecoder(w.Body).Decode(&resp) - assert.NoError(ttt, err) + assert.NoError(t, err) - assert.NotEmpty(ttt, resp.CredentialJWT) - assert.NotEmpty(ttt, resp.Credential.CredentialStatus) - assert.Equal(ttt, resp.Credential.Issuer, issuerDID.DID.ID) + assert.NotEmpty(t, resp.CredentialJWT) + assert.NotEmpty(t, resp.Credential.CredentialStatus) + assert.Equal(t, resp.Credential.Issuer, issuerDID.DID.ID) credStatusMap, ok := resp.Credential.CredentialStatus.(map[string]any) - assert.True(ttt, ok) + assert.True(t, ok) - assert.NotEmpty(ttt, credStatusMap["statusListIndex"]) + assert.NotEmpty(t, credStatusMap["statusListIndex"]) credStatusListID := (credStatusMap["statusListCredential"]).(string) - assert.NotEmpty(ttt, credStatusListID) + assert.NotEmpty(t, credStatusListID) i := strings.LastIndex(credStatusListID, "/") uuidStringUUID := credStatusListID[i+1:] @@ -1315,15 +1315,15 @@ func TestCredentialAPI(t *testing.T) { req = httptest.NewRequest(http.MethodGet, fmt.Sprintf("https://localhost:8080/%s", credStatusListID), nil) c = newRequestContextWithParams(w, req, map[string]string{"id": uuidStringUUID}) credRouter.GetCredentialStatusList(c) - assert.True(ttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var credListResp router.GetCredentialStatusListResponse err = json.NewDecoder(w.Body).Decode(&credListResp) - assert.NoError(ttt, err) + assert.NoError(t, err) - assert.NotEmpty(ttt, credListResp.CredentialJWT) - assert.Empty(ttt, credListResp.Credential.CredentialStatus) - assert.Equal(ttt, credListResp.Credential.ID, credStatusListID) + assert.NotEmpty(t, credListResp.CredentialJWT) + assert.Empty(t, credListResp.Credential.CredentialStatus) + assert.Equal(t, credListResp.Credential.ID, credStatusListID) }) }) } diff --git a/pkg/server/server_did_test.go b/pkg/server/server_did_test.go index fa2717814..6517762a7 100644 --- a/pkg/server/server_did_test.go +++ b/pkg/server/server_did_test.go @@ -32,12 +32,12 @@ func TestDIDAPI(t *testing.T) { for _, test := range testutil.TestDatabases { t.Run(test.Name, func(t *testing.T) { - t.Run("Test Get DID Methods", func(tt *testing.T) { - db := test.ServiceStorage(tt) - require.NotEmpty(tt, db) + t.Run("Test Get DID Methods", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - _, keyStoreService, _ := testKeyStore(tt, db) - didService, _ := testDIDRouter(tt, db, keyStoreService, []string{"key", "web", "ion"}, nil) + _, keyStoreService, _ := testKeyStore(t, db) + didService, _ := testDIDRouter(t, db, keyStoreService, []string{"key", "web", "ion"}, nil) // get DID method req := httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/dids", nil) @@ -45,24 +45,24 @@ func TestDIDAPI(t *testing.T) { c := newRequestContext(w, req) didService.ListDIDMethods(c) - assert.Equal(tt, http.StatusOK, w.Result().StatusCode) + assert.Equal(t, http.StatusOK, w.Result().StatusCode) var resp router.ListDIDMethodsResponse err := json.NewDecoder(w.Body).Decode(&resp) - assert.NoError(tt, err) + assert.NoError(t, err) - assert.Len(tt, resp.DIDMethods, 3) - assert.Contains(tt, resp.DIDMethods, didsdk.KeyMethod) - assert.Contains(tt, resp.DIDMethods, didsdk.WebMethod) - assert.Contains(tt, resp.DIDMethods, didsdk.IONMethod) + assert.Len(t, resp.DIDMethods, 3) + assert.Contains(t, resp.DIDMethods, didsdk.KeyMethod) + assert.Contains(t, resp.DIDMethods, didsdk.WebMethod) + assert.Contains(t, resp.DIDMethods, didsdk.IONMethod) }) - t.Run("Test Create DID By Method: Key", func(tt *testing.T) { - db := test.ServiceStorage(tt) - require.NotEmpty(tt, db) + t.Run("Test Create DID By Method: Key", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - _, keyStoreService, _ := testKeyStore(tt, db) - didService, _ := testDIDRouter(tt, db, keyStoreService, []string{"key"}, nil) + _, keyStoreService, _ := testKeyStore(t, db) + didService, _ := testDIDRouter(t, db, keyStoreService, []string{"key"}, nil) // create DID by method - key - missing body req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/dids/key", nil) @@ -70,44 +70,44 @@ func TestDIDAPI(t *testing.T) { params := map[string]string{"method": "key"} c := newRequestContextWithParams(w, req, params) didService.CreateDIDByMethod(c) - assert.Contains(tt, w.Body.String(), "invalid create DID request") + assert.Contains(t, w.Body.String(), "invalid create DID request") // reset recorder between calls w = httptest.NewRecorder() // with body, bad key type createDIDRequest := router.CreateDIDByMethodRequest{KeyType: "bad"} - requestReader := newRequestValue(tt, createDIDRequest) + requestReader := newRequestValue(t, createDIDRequest) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/dids/key", requestReader) c = newRequestContextWithParams(w, req, params) didService.CreateDIDByMethod(c) - assert.Contains(tt, w.Body.String(), "could not create DID for method with key type: bad") + assert.Contains(t, w.Body.String(), "could not create DID for method with key type: bad") // reset recorder between calls w = httptest.NewRecorder() // with body, good key type createDIDRequest = router.CreateDIDByMethodRequest{KeyType: crypto.Ed25519} - requestReader = newRequestValue(tt, createDIDRequest) + requestReader = newRequestValue(t, createDIDRequest) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/dids/key", requestReader) c = newRequestContextWithParams(w, req, params) didService.CreateDIDByMethod(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.CreateDIDByMethodResponse err := json.NewDecoder(w.Body).Decode(&resp) - assert.NoError(tt, err) - assert.Contains(tt, resp.DID.ID, didsdk.KeyMethod) + assert.NoError(t, err) + assert.Contains(t, resp.DID.ID, didsdk.KeyMethod) }) - t.Run("Test Create DID By Method: Web", func(tt *testing.T) { - db := test.ServiceStorage(tt) - require.NotEmpty(tt, db) + t.Run("Test Create DID By Method: Web", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - _, keyStoreService, _ := testKeyStore(tt, db) - didService, _ := testDIDRouter(tt, db, keyStoreService, []string{"web"}, nil) + _, keyStoreService, _ := testKeyStore(t, db) + didService, _ := testDIDRouter(t, db, keyStoreService, []string{"web"}, nil) // create DID by method - web - missing body req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/dids/web", nil) @@ -118,19 +118,19 @@ func TestDIDAPI(t *testing.T) { c := newRequestContextWithParams(w, req, params) didService.CreateDIDByMethod(c) - assert.Contains(tt, w.Body.String(), "invalid create DID request") + assert.Contains(t, w.Body.String(), "invalid create DID request") // reset recorder between calls w = httptest.NewRecorder() // with body, good key type, missing options createDIDRequest := router.CreateDIDByMethodRequest{KeyType: crypto.Ed25519} - requestReader := newRequestValue(tt, createDIDRequest) + requestReader := newRequestValue(t, createDIDRequest) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/dids/web", requestReader) c = newRequestContextWithParams(w, req, params) didService.CreateDIDByMethod(c) - assert.Contains(tt, w.Body.String(), "could not create DID for method with key type: Ed25519: options cannot be empty") + assert.Contains(t, w.Body.String(), "could not create DID for method with key type: Ed25519: options cannot be empty") // reset recorder between calls w = httptest.NewRecorder() @@ -140,12 +140,12 @@ func TestDIDAPI(t *testing.T) { // with body, bad key type createDIDRequest = router.CreateDIDByMethodRequest{KeyType: "bad", Options: options} - requestReader = newRequestValue(tt, createDIDRequest) + requestReader = newRequestValue(t, createDIDRequest) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/dids/web", requestReader) c = newRequestContextWithParams(w, req, params) didService.CreateDIDByMethod(c) - assert.Contains(tt, w.Body.String(), "could not create DID for method with key type: bad") + assert.Contains(t, w.Body.String(), "could not create DID for method with key type: bad") // reset recorder between calls w = httptest.NewRecorder() @@ -156,7 +156,7 @@ func TestDIDAPI(t *testing.T) { Options: options, } - requestReader = newRequestValue(tt, createDIDRequest) + requestReader = newRequestValue(t, createDIDRequest) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/dids/web", requestReader) gock.New("https://example.com"). @@ -167,20 +167,20 @@ func TestDIDAPI(t *testing.T) { c = newRequestContextWithParams(w, req, params) didService.CreateDIDByMethod(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.CreateDIDByMethodResponse err := json.NewDecoder(w.Body).Decode(&resp) - assert.NoError(tt, err) - assert.Contains(tt, resp.DID.ID, didsdk.WebMethod) + assert.NoError(t, err) + assert.Contains(t, resp.DID.ID, didsdk.WebMethod) }) - t.Run("Test Create DID By Method: ION", func(tt *testing.T) { - db := test.ServiceStorage(tt) - require.NotEmpty(tt, db) + t.Run("Test Create DID By Method: ION", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - _, keyStoreService, _ := testKeyStore(tt, db) - didRouter, _ := testDIDRouter(tt, db, keyStoreService, []string{"ion"}, nil) + _, keyStoreService, _ := testKeyStore(t, db) + didRouter, _ := testDIDRouter(t, db, keyStoreService, []string{"ion"}, nil) // create DID by method - ion - missing body req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/dids/ion", nil) @@ -191,7 +191,7 @@ func TestDIDAPI(t *testing.T) { c := newRequestContextWithParams(w, req, params) didRouter.CreateDIDByMethod(c) - assert.Contains(tt, w.Body.String(), "invalid create DID request") + assert.Contains(t, w.Body.String(), "invalid create DID request") // reset recorder between calls w = httptest.NewRecorder() @@ -204,12 +204,12 @@ func TestDIDAPI(t *testing.T) { // with body, good key type, no options createDIDRequest := router.CreateDIDByMethodRequest{KeyType: crypto.Ed25519} - requestReader := newRequestValue(tt, createDIDRequest) + requestReader := newRequestValue(t, createDIDRequest) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/dids/ion", requestReader) c = newRequestContextWithParams(w, req, params) didRouter.CreateDIDByMethod(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) // reset recorder between calls w = httptest.NewRecorder() @@ -219,12 +219,12 @@ func TestDIDAPI(t *testing.T) { // with body, bad key type createDIDRequest = router.CreateDIDByMethodRequest{KeyType: "bad", Options: options} - requestReader = newRequestValue(tt, createDIDRequest) + requestReader = newRequestValue(t, createDIDRequest) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/dids/ion", requestReader) c = newRequestContextWithParams(w, req, params) didRouter.CreateDIDByMethod(c) - assert.Contains(tt, w.Body.String(), "could not create DID for method with key type: bad") + assert.Contains(t, w.Body.String(), "could not create DID for method with key type: bad") // reset recorder between calls w = httptest.NewRecorder() @@ -234,7 +234,7 @@ func TestDIDAPI(t *testing.T) { KeyType: crypto.Ed25519, Options: options, } - requestReader = newRequestValue(tt, createDIDRequest) + requestReader = newRequestValue(t, createDIDRequest) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/dids/ion", requestReader) gock.New(testIONResolverURL). @@ -244,12 +244,12 @@ func TestDIDAPI(t *testing.T) { c = newRequestContextWithParams(w, req, params) didRouter.CreateDIDByMethod(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.CreateDIDByMethodResponse err := json.NewDecoder(w.Body).Decode(&resp) - assert.NoError(tt, err) - assert.Contains(tt, resp.DID.ID, didsdk.IONMethod) + assert.NoError(t, err) + assert.Contains(t, resp.DID.ID, didsdk.IONMethod) gock.Off() // good params @@ -260,20 +260,20 @@ func TestDIDAPI(t *testing.T) { } c = newRequestContextWithParams(w, req, goodParams) didRouter.GetDIDByMethod(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var getDIDResp router.GetDIDByMethodResponse err = json.NewDecoder(w.Body).Decode(&getDIDResp) - assert.NoError(tt, err) - assert.Equal(tt, resp.DID.ID, getDIDResp.DID.ID) + assert.NoError(t, err) + assert.Equal(t, resp.DID.ID, getDIDResp.DID.ID) }) - t.Run("Test Update DID By Method: ION", func(tt *testing.T) { + t.Run("Test Update DID By Method: ION", func(t *testing.T) { db := test.ServiceStorage(t) - require.NotEmpty(tt, db) + require.NotEmpty(t, db) - _, keyStoreService, keyStoreServiceFactory := testKeyStore(tt, db) - didService, _ := testDIDRouter(tt, db, keyStoreService, []string{"ion"}, keyStoreServiceFactory) + _, keyStoreService, keyStoreServiceFactory := testKeyStore(t, db) + didService, _ := testDIDRouter(t, db, keyStoreService, []string{"ion"}, keyStoreServiceFactory) params := map[string]string{ "method": "ion", @@ -289,16 +289,16 @@ func TestDIDAPI(t *testing.T) { // with body, good key type, no options createDIDRequest := router.CreateDIDByMethodRequest{KeyType: crypto.Ed25519} - requestReader := newRequestValue(tt, createDIDRequest) + requestReader := newRequestValue(t, createDIDRequest) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/dids/ion", requestReader) c := newRequestContextWithParams(w, req, params) didService.CreateDIDByMethod(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var createDIDResponse router.CreateDIDByMethodResponse err := json.NewDecoder(w.Body).Decode(&createDIDResponse) - assert.NoError(tt, err) + assert.NoError(t, err) updateDIDRequest := router.UpdateDIDByMethodRequest{ StateChange: router.StateChange{ @@ -321,7 +321,7 @@ func TestDIDAPI(t *testing.T) { } w = httptest.NewRecorder() params["id"] = createDIDResponse.DID.ID - requestReader = newRequestValue(tt, updateDIDRequest) + requestReader = newRequestValue(t, updateDIDRequest) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/dids/ion/"+createDIDResponse.DID.ID, requestReader) gock.New(testIONResolverURL). @@ -332,7 +332,7 @@ func TestDIDAPI(t *testing.T) { c = newRequestContextWithParams(w, req, params) didService.UpdateDIDByMethod(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) updateDIDRequest2 := router.UpdateDIDByMethodRequest{ StateChange: router.StateChange{ @@ -346,7 +346,7 @@ func TestDIDAPI(t *testing.T) { }, } w = httptest.NewRecorder() - requestReader = newRequestValue(tt, updateDIDRequest2) + requestReader = newRequestValue(t, updateDIDRequest2) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/dids/ion/"+createDIDResponse.DID.ID, requestReader) gock.New(testIONResolverURL). @@ -357,32 +357,32 @@ func TestDIDAPI(t *testing.T) { c = newRequestContextWithParams(w, req, params) didService.UpdateDIDByMethod(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var updateDIDResponse router.UpdateDIDByMethodResponse err = json.NewDecoder(w.Body).Decode(&updateDIDResponse) - assert.NoError(tt, err) - assert.Contains(tt, updateDIDResponse.DID.ID, didsdk.IONMethod) + assert.NoError(t, err) + assert.Contains(t, updateDIDResponse.DID.ID, didsdk.IONMethod) - assert.Equal(tt, "#testService1Id", updateDIDResponse.DID.Services[0].ID) + assert.Equal(t, "#testService1Id", updateDIDResponse.DID.Services[0].ID) // Check that the correct updates were performed. - assert.Len(tt, updateDIDResponse.DID.VerificationMethod, 1+len(createDIDResponse.DID.VerificationMethod)) - assert.Equal(tt, createDIDResponse.DID.VerificationMethod[0].ID, updateDIDResponse.DID.VerificationMethod[0].ID) - assert.Equal(tt, "#testPublicKeyModel1Id", updateDIDResponse.DID.VerificationMethod[1].ID) - assert.Len(tt, updateDIDResponse.DID.Authentication, 1+len(createDIDResponse.DID.Authentication)) - assert.Len(tt, updateDIDResponse.DID.AssertionMethod, 0+len(createDIDResponse.DID.AssertionMethod)) - assert.Len(tt, updateDIDResponse.DID.KeyAgreement, 1+len(createDIDResponse.DID.KeyAgreement)) - assert.Len(tt, updateDIDResponse.DID.CapabilityInvocation, 0+len(createDIDResponse.DID.CapabilityInvocation)) - assert.Len(tt, updateDIDResponse.DID.CapabilityInvocation, 0+len(createDIDResponse.DID.CapabilityInvocation)) + assert.Len(t, updateDIDResponse.DID.VerificationMethod, 1+len(createDIDResponse.DID.VerificationMethod)) + assert.Equal(t, createDIDResponse.DID.VerificationMethod[0].ID, updateDIDResponse.DID.VerificationMethod[0].ID) + assert.Equal(t, "#testPublicKeyModel1Id", updateDIDResponse.DID.VerificationMethod[1].ID) + assert.Len(t, updateDIDResponse.DID.Authentication, 1+len(createDIDResponse.DID.Authentication)) + assert.Len(t, updateDIDResponse.DID.AssertionMethod, 0+len(createDIDResponse.DID.AssertionMethod)) + assert.Len(t, updateDIDResponse.DID.KeyAgreement, 1+len(createDIDResponse.DID.KeyAgreement)) + assert.Len(t, updateDIDResponse.DID.CapabilityInvocation, 0+len(createDIDResponse.DID.CapabilityInvocation)) + assert.Len(t, updateDIDResponse.DID.CapabilityInvocation, 0+len(createDIDResponse.DID.CapabilityInvocation)) }) - t.Run("Test Create Duplicate DID:Webs", func(tt *testing.T) { - db := test.ServiceStorage(tt) - require.NotEmpty(tt, db) + t.Run("Test Create Duplicate DID:Webs", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - _, keyStoreService, _ := testKeyStore(tt, db) - didService, _ := testDIDRouter(tt, db, keyStoreService, []string{"web"}, nil) + _, keyStoreService, _ := testKeyStore(t, db) + didService, _ := testDIDRouter(t, db, keyStoreService, []string{"web"}, nil) // reset recorder between calls w := httptest.NewRecorder() @@ -400,7 +400,7 @@ func TestDIDAPI(t *testing.T) { Options: options, } - requestReader := newRequestValue(tt, createDIDRequest) + requestReader := newRequestValue(t, createDIDRequest) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/dids/web", requestReader) gock.New("https://example.com"). @@ -410,17 +410,17 @@ func TestDIDAPI(t *testing.T) { c := newRequestContextWithParams(w, req, params) didService.CreateDIDByMethod(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.CreateDIDByMethodResponse err := json.NewDecoder(w.Body).Decode(&resp) - assert.NoError(tt, err) - assert.Contains(tt, resp.DID.ID, didsdk.WebMethod) + assert.NoError(t, err) + assert.Contains(t, resp.DID.ID, didsdk.WebMethod) // reset recorder between calls w = httptest.NewRecorder() - requestReader2 := newRequestValue(tt, createDIDRequest) + requestReader2 := newRequestValue(t, createDIDRequest) req2 := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/dids/web", requestReader2) gock.New("https://example.com"). Get("/.well-known/did.json"). @@ -430,17 +430,17 @@ func TestDIDAPI(t *testing.T) { // Make sure it can't make another did:web of the same DIDWebID c = newRequestContextWithParams(w, req2, params) didService.CreateDIDByMethod(c) - assert.Equal(tt, w.Code, 500) + assert.Equal(t, w.Code, 500) - assert.Contains(tt, w.Body.String(), "already exists") + assert.Contains(t, w.Body.String(), "already exists") }) - t.Run("Test Get DID By Method", func(tt *testing.T) { - db := test.ServiceStorage(tt) - require.NotEmpty(tt, db) + t.Run("Test Get DID By Method", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - _, keyStore, _ := testKeyStore(tt, db) - didService, _ := testDIDRouter(tt, db, keyStore, []string{"key"}, nil) + _, keyStore, _ := testKeyStore(t, db) + didService, _ := testDIDRouter(t, db, keyStore, []string{"key"}, nil) // get DID by method req := httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/dids/bad/worse", nil) @@ -453,7 +453,7 @@ func TestDIDAPI(t *testing.T) { } c := newRequestContextWithParams(w, req, badParams) didService.GetDIDByMethod(c) - assert.Contains(tt, w.Body.String(), "could not get DID for method") + assert.Contains(t, w.Body.String(), "could not get DID for method") // reset recorder between calls w = httptest.NewRecorder() @@ -465,24 +465,24 @@ func TestDIDAPI(t *testing.T) { } c = newRequestContextWithParams(w, req, badParams1) didService.GetDIDByMethod(c) - assert.Contains(tt, w.Body.String(), "could not get DID for method with id: worse") + assert.Contains(t, w.Body.String(), "could not get DID for method with id: worse") // reset recorder between calls w = httptest.NewRecorder() // store a DID createDIDRequest := router.CreateDIDByMethodRequest{KeyType: crypto.Ed25519} - requestReader := newRequestValue(tt, createDIDRequest) + requestReader := newRequestValue(t, createDIDRequest) params := map[string]string{"method": "key"} req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/dids/key", requestReader) c = newRequestContextWithParams(w, req, params) didService.CreateDIDByMethod(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var createdDID router.CreateDIDByMethodResponse err := json.NewDecoder(w.Body).Decode(&createdDID) - assert.NoError(tt, err) + assert.NoError(t, err) // reset recorder between calls w = httptest.NewRecorder() @@ -499,20 +499,20 @@ func TestDIDAPI(t *testing.T) { } c = newRequestContextWithParams(w, req, goodParams) didService.GetDIDByMethod(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.GetDIDByMethodResponse err = json.NewDecoder(w.Body).Decode(&resp) - assert.NoError(tt, err) - assert.Equal(tt, createdID, resp.DID.ID) + assert.NoError(t, err) + assert.Equal(t, createdID, resp.DID.ID) }) - t.Run("Test Soft Delete DID By Method", func(tt *testing.T) { - db := test.ServiceStorage(tt) - require.NotEmpty(tt, db) + t.Run("Test Soft Delete DID By Method", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - _, keyStore, _ := testKeyStore(tt, db) - didService, _ := testDIDRouter(tt, db, keyStore, []string{"key"}, nil) + _, keyStore, _ := testKeyStore(t, db) + didService, _ := testDIDRouter(t, db, keyStore, []string{"key"}, nil) // soft delete DID by method req := httptest.NewRequest(http.MethodDelete, "https://ssi-service.com/v1/dids/bad/worse", nil) @@ -526,7 +526,7 @@ func TestDIDAPI(t *testing.T) { c := newRequestContextWithParams(w, req, badParams) didService.SoftDeleteDIDByMethod(c) - assert.Contains(tt, w.Body.String(), "could not soft delete DID") + assert.Contains(t, w.Body.String(), "could not soft delete DID") // good method, bad id badParams1 := map[string]string{ @@ -536,34 +536,34 @@ func TestDIDAPI(t *testing.T) { w = httptest.NewRecorder() c = newRequestContextWithParams(w, req, badParams1) didService.SoftDeleteDIDByMethod(c) - assert.Contains(tt, w.Body.String(), "could not soft delete DID with id: worse: error getting DID: worse") + assert.Contains(t, w.Body.String(), "could not soft delete DID with id: worse: error getting DID: worse") // store a DID createDIDRequest := router.CreateDIDByMethodRequest{KeyType: crypto.Ed25519} - requestReader := newRequestValue(tt, createDIDRequest) + requestReader := newRequestValue(t, createDIDRequest) params := map[string]string{"method": "key"} req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/dids/key", requestReader) w = httptest.NewRecorder() c = newRequestContextWithParams(w, req, params) didService.CreateDIDByMethod(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var createdDID router.CreateDIDByMethodResponse err := json.NewDecoder(w.Body).Decode(&createdDID) - assert.NoError(tt, err) + assert.NoError(t, err) // get all dids for method req = httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/dids/key", requestReader) w = httptest.NewRecorder() c = newRequestContextWithParams(w, req, params) didService.ListDIDsByMethod(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var gotDIDsResponse router.ListDIDsByMethodResponse err = json.NewDecoder(w.Body).Decode(&gotDIDsResponse) - assert.NoError(tt, err) - assert.Len(tt, gotDIDsResponse.DIDs, 1) + assert.NoError(t, err) + assert.Len(t, gotDIDsResponse.DIDs, 1) // get it back createdID := createdDID.DID.ID @@ -578,12 +578,12 @@ func TestDIDAPI(t *testing.T) { w = httptest.NewRecorder() c = newRequestContextWithParams(w, req, goodParams) didService.GetDIDByMethod(c) - assert.NoError(tt, err) + assert.NoError(t, err) var resp router.GetDIDByMethodResponse err = json.NewDecoder(w.Body).Decode(&resp) - assert.NoError(tt, err) - assert.Equal(tt, createdID, resp.DID.ID) + assert.NoError(t, err) + assert.Equal(t, createdID, resp.DID.ID) // delete it deleteDIDPath := fmt.Sprintf("https://ssi-service.com/v1/dids/key/%s", createdID) @@ -592,7 +592,7 @@ func TestDIDAPI(t *testing.T) { w = httptest.NewRecorder() c = newRequestContextWithParams(w, req, goodParams) didService.SoftDeleteDIDByMethod(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) // get it back req = httptest.NewRequest(http.MethodGet, getDIDPath, nil) @@ -600,43 +600,43 @@ func TestDIDAPI(t *testing.T) { w = httptest.NewRecorder() c = newRequestContextWithParams(w, req, goodParams) didService.GetDIDByMethod(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var deletedGetResp router.GetDIDByMethodResponse err = json.NewDecoder(w.Body).Decode(&deletedGetResp) - assert.NoError(tt, err) - assert.Equal(tt, createdID, deletedGetResp.DID.ID) + assert.NoError(t, err) + assert.Equal(t, createdID, deletedGetResp.DID.ID) // get all dids for method req = httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/dids/key", requestReader) w = httptest.NewRecorder() c = newRequestContextWithParams(w, req, params) didService.ListDIDsByMethod(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var gotDIDsResponseAfterDelete router.ListDIDsByMethodResponse err = json.NewDecoder(w.Body).Decode(&gotDIDsResponseAfterDelete) - assert.NoError(tt, err) - assert.Len(tt, gotDIDsResponseAfterDelete.DIDs, 0) + assert.NoError(t, err) + assert.Len(t, gotDIDsResponseAfterDelete.DIDs, 0) // get all deleted dids for method req = httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/dids/key?deleted=true", requestReader) w = httptest.NewRecorder() c = newRequestContextWithParams(w, req, params) didService.ListDIDsByMethod(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var gotDeletedDIDsResponseAfterDelete router.ListDIDsByMethodResponse err = json.NewDecoder(w.Body).Decode(&gotDeletedDIDsResponseAfterDelete) - assert.NoError(tt, err) - assert.Len(tt, gotDeletedDIDsResponseAfterDelete.DIDs, 1) + assert.NoError(t, err) + assert.Len(t, gotDeletedDIDsResponseAfterDelete.DIDs, 1) }) - t.Run("List DIDs made up token fails", func(tt *testing.T) { - db := test.ServiceStorage(tt) - require.NotEmpty(tt, db) - _, keyStore, _ := testKeyStore(tt, db) - didService, _ := testDIDRouter(tt, db, keyStore, []string{"key", "web"}, nil) + t.Run("List DIDs made up token fails", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) + _, keyStore, _ := testKeyStore(t, db) + didService, _ := testDIDRouter(t, db, keyStore, []string{"key", "web"}, nil) w := httptest.NewRecorder() badParams := url.Values{ @@ -646,18 +646,18 @@ func TestDIDAPI(t *testing.T) { req := httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/dids/key?"+badParams.Encode(), nil) c := newRequestContextWithParams(w, req, map[string]string{"method": "key"}) didService.ListDIDsByMethod(c) - assert.Contains(tt, w.Body.String(), "token value cannot be decoded") + assert.Contains(t, w.Body.String(), "token value cannot be decoded") }) - t.Run("List DIDs pagination", func(tt *testing.T) { + t.Run("List DIDs pagination", func(t *testing.T) { if !strings.Contains(test.Name, "Redis") { - db := test.ServiceStorage(tt) - require.NotEmpty(tt, db) - _, keyStore, _ := testKeyStore(tt, db) - didRouter, _ := testDIDRouter(tt, db, keyStore, []string{"key", "web"}, nil) + db := test.ServiceStorage(t) + require.NotEmpty(t, db) + _, keyStore, _ := testKeyStore(t, db) + didRouter, _ := testDIDRouter(t, db, keyStore, []string{"key", "web"}, nil) - createDIDWithRouter(tt, didRouter) - createDIDWithRouter(tt, didRouter) + createDIDWithRouter(t, didRouter) + createDIDWithRouter(t, didRouter) w := httptest.NewRecorder() params := url.Values{ @@ -670,9 +670,9 @@ func TestDIDAPI(t *testing.T) { var listDIDsByMethodResponse router.ListDIDsByMethodResponse err := json.NewDecoder(w.Body).Decode(&listDIDsByMethodResponse) - assert.NoError(tt, err) - assert.NotEmpty(tt, listDIDsByMethodResponse.NextPageToken) - assert.Len(tt, listDIDsByMethodResponse.DIDs, 1) + assert.NoError(t, err) + assert.NotEmpty(t, listDIDsByMethodResponse.NextPageToken) + assert.Len(t, listDIDsByMethodResponse.DIDs, 1) w = httptest.NewRecorder() params["pageToken"] = []string{listDIDsByMethodResponse.NextPageToken} @@ -683,20 +683,20 @@ func TestDIDAPI(t *testing.T) { var listDIDsByMethodResponse2 router.ListDIDsByMethodResponse err = json.NewDecoder(w.Body).Decode(&listDIDsByMethodResponse2) - assert.NoError(tt, err) - assert.Empty(tt, listDIDsByMethodResponse2.NextPageToken) - assert.Len(tt, listDIDsByMethodResponse2.DIDs, 1) + assert.NoError(t, err) + assert.Empty(t, listDIDsByMethodResponse2.NextPageToken) + assert.Len(t, listDIDsByMethodResponse2.DIDs, 1) } }) - t.Run("List DIDs pagination change query between calls returns error", func(tt *testing.T) { + t.Run("List DIDs pagination change query between calls returns error", func(t *testing.T) { if !strings.Contains(test.Name, "Redis") { - db := test.ServiceStorage(tt) - require.NotEmpty(tt, db) - _, keyStore, _ := testKeyStore(tt, db) - didRouter, _ := testDIDRouter(tt, db, keyStore, []string{"key", "web"}, nil) - createDIDWithRouter(tt, didRouter) - createDIDWithRouter(tt, didRouter) + db := test.ServiceStorage(t) + require.NotEmpty(t, db) + _, keyStore, _ := testKeyStore(t, db) + didRouter, _ := testDIDRouter(t, db, keyStore, []string{"key", "web"}, nil) + createDIDWithRouter(t, didRouter) + createDIDWithRouter(t, didRouter) w := httptest.NewRecorder() params := url.Values{ @@ -706,13 +706,13 @@ func TestDIDAPI(t *testing.T) { c := newRequestContextWithParams(w, req, map[string]string{"method": "key"}) didRouter.ListDIDsByMethod(c) - assert.True(tt, util.Is2xxResponse(w.Result().StatusCode)) + assert.True(t, util.Is2xxResponse(w.Result().StatusCode)) var listDIDsByMethodResponse router.ListDIDsByMethodResponse err := json.NewDecoder(w.Body).Decode(&listDIDsByMethodResponse) - assert.NoError(tt, err) - assert.NotEmpty(tt, listDIDsByMethodResponse.NextPageToken) - assert.Len(tt, listDIDsByMethodResponse.DIDs, 1) + assert.NoError(t, err) + assert.NotEmpty(t, listDIDsByMethodResponse.NextPageToken) + assert.Len(t, listDIDsByMethodResponse.DIDs, 1) w = httptest.NewRecorder() params["pageToken"] = []string{listDIDsByMethodResponse.NextPageToken} @@ -720,16 +720,16 @@ func TestDIDAPI(t *testing.T) { req = httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/dids/key?"+params.Encode(), nil) c = newRequestContextWithParams(w, req, map[string]string{"method": "key"}) didRouter.ListDIDsByMethod(c) - assert.Equal(tt, http.StatusBadRequest, w.Result().StatusCode) - assert.Contains(tt, w.Body.String(), "page token must be for the same query") + assert.Equal(t, http.StatusBadRequest, w.Result().StatusCode) + assert.Contains(t, w.Body.String(), "page token must be for the same query") } }) - t.Run("Test Get DIDs By Method", func(tt *testing.T) { - db := test.ServiceStorage(tt) - require.NotEmpty(tt, db) - _, keyStore, _ := testKeyStore(tt, db) - didService, _ := testDIDRouter(tt, db, keyStore, []string{"key", "web"}, nil) + t.Run("Test Get DIDs By Method", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) + _, keyStore, _ := testKeyStore(t, db) + didService, _ := testDIDRouter(t, db, keyStore, []string{"key", "web"}, nil) // get DIDs by method req := httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/dids/bad", nil) @@ -741,7 +741,7 @@ func TestDIDAPI(t *testing.T) { } c := newRequestContextWithParams(w, req, badParams) didService.ListDIDsByMethod(c) - assert.Contains(tt, w.Body.String(), "could not get DIDs for method: bad") + assert.Contains(t, w.Body.String(), "could not get DIDs for method: bad") w = httptest.NewRecorder() @@ -749,42 +749,42 @@ func TestDIDAPI(t *testing.T) { goodParams := map[string]string{"method": "key"} c = newRequestContextWithParams(w, req, goodParams) didService.ListDIDsByMethod(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var gotDIDs router.GetDIDByMethodResponse err := json.NewDecoder(w.Body).Decode(&gotDIDs) - assert.NoError(tt, err) - assert.Empty(tt, gotDIDs) + assert.NoError(t, err) + assert.Empty(t, gotDIDs) // reset recorder between calls w = httptest.NewRecorder() // store two DIDs createDIDRequest := router.CreateDIDByMethodRequest{KeyType: crypto.Ed25519} - requestReader := newRequestValue(tt, createDIDRequest) + requestReader := newRequestValue(t, createDIDRequest) params := map[string]string{"method": "key"} req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/dids/key", requestReader) c = newRequestContextWithParams(w, req, params) didService.CreateDIDByMethod(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var createdDID router.CreateDIDByMethodResponse err = json.NewDecoder(w.Body).Decode(&createdDID) - assert.NoError(tt, err) + assert.NoError(t, err) // reset recorder between calls w = httptest.NewRecorder() - requestReader = newRequestValue(tt, createDIDRequest) + requestReader = newRequestValue(t, createDIDRequest) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/dids/key", requestReader) c = newRequestContextWithParams(w, req, params) didService.CreateDIDByMethod(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var createdDID2 router.CreateDIDByMethodResponse err = json.NewDecoder(w.Body).Decode(&createdDID2) - assert.NoError(tt, err) + assert.NoError(t, err) // reset recorder between calls w = httptest.NewRecorder() @@ -793,29 +793,29 @@ func TestDIDAPI(t *testing.T) { req = httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/dids/key", requestReader) c = newRequestContextWithParams(w, req, params) didService.ListDIDsByMethod(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var gotDIDsResponse router.ListDIDsByMethodResponse err = json.NewDecoder(w.Body).Decode(&gotDIDsResponse) - assert.NoError(tt, err) + assert.NoError(t, err) knownDIDs := map[string]bool{createdDID.DID.ID: true, createdDID2.DID.ID: true} for _, id := range gotDIDsResponse.DIDs { if _, ok := knownDIDs[id.ID]; !ok { - tt.Error("got unknown DID") + t.Error("got unknown DID") } else { delete(knownDIDs, id.ID) } } - assert.Len(tt, knownDIDs, 0) + assert.Len(t, knownDIDs, 0) }) - t.Run("Test Resolve DIDs", func(tt *testing.T) { - db := test.ServiceStorage(tt) - require.NotEmpty(tt, db) + t.Run("Test Resolve DIDs", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - _, keyStore, _ := testKeyStore(tt, db) - didService, _ := testDIDRouter(tt, db, keyStore, []string{"key", "web"}, nil) + _, keyStore, _ := testKeyStore(t, db) + didService, _ := testDIDRouter(t, db, keyStore, []string{"key", "web"}, nil) // bad resolution request req := httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/dids/resolver/bad", nil) @@ -824,7 +824,7 @@ func TestDIDAPI(t *testing.T) { badParams := map[string]string{"id": "bad"} c := newRequestContextWithParams(w, req, badParams) didService.ResolveDID(c) - assert.Contains(tt, w.Body.String(), "malformed did") + assert.Contains(t, w.Body.String(), "malformed did") w = httptest.NewRecorder() @@ -835,7 +835,7 @@ func TestDIDAPI(t *testing.T) { } c = newRequestContextWithParams(w, req, badParams) didService.ResolveDID(c) - assert.Contains(tt, w.Body.String(), "unable to resolve DID did:key:abcd") + assert.Contains(t, w.Body.String(), "unable to resolve DID did:key:abcd") w = httptest.NewRecorder() @@ -846,13 +846,13 @@ func TestDIDAPI(t *testing.T) { } c = newRequestContextWithParams(w, req, goodParams) didService.ResolveDID(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resolutionResponse router.ResolveDIDResponse err := json.NewDecoder(w.Body).Decode(&resolutionResponse) - assert.NoError(tt, err) - assert.NotEmpty(tt, resolutionResponse.DIDDocument) - assert.Equal(tt, "did:key:z6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLVVQR3djdX3mDooWp", resolutionResponse.DIDDocument.ID) + assert.NoError(t, err) + assert.NotEmpty(t, resolutionResponse.DIDDocument) + assert.Equal(t, "did:key:z6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLVVQR3djdX3mDooWp", resolutionResponse.DIDDocument.ID) }) }) } @@ -880,71 +880,71 @@ func TestBatchCreateDIDs(t *testing.T) { } _, batchDIDRouter := testDIDRouter(t, db, keyStoreService, []string{"key"}, factory) - t.Run(" Batch Create DID By Method: Key", func(tt *testing.T) { + t.Run(" Batch Create DID By Method: Key", func(t *testing.T) { w := httptest.NewRecorder() - requestReader := newRequestValue(tt, createDIDRequest) + requestReader := newRequestValue(t, createDIDRequest) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/dids/key", requestReader) params := map[string]string{"method": "key"} c := newRequestContextWithParams(w, req, params) batchDIDRouter.BatchCreateDIDs(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.BatchCreateDIDsResponse err := json.NewDecoder(w.Body).Decode(&resp) - assert.NoError(tt, err) - assert.Len(tt, resp.DIDs, 3) + assert.NoError(t, err) + assert.Len(t, resp.DIDs, 3) }) - t.Run("Fails with malformed request", func(ttt *testing.T) { + t.Run("Fails with malformed request", func(t *testing.T) { createDIDRequest := createDIDRequest // missing the data field createDIDRequest.Requests = append(createDIDRequest.Requests, router.CreateDIDByMethodRequest{ KeyType: "bad", }) - requestValue := newRequestValue(ttt, createDIDRequest) + requestValue := newRequestValue(t, createDIDRequest) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/dids/key/batch", requestValue) w := httptest.NewRecorder() params := map[string]string{"method": "key"} c := newRequestContextWithParams(w, req, params) batchDIDRouter.BatchCreateDIDs(c) - assert.Equal(ttt, http.StatusInternalServerError, w.Code) - assert.Contains(ttt, w.Body.String(), "unsupported did:key type: bad") + assert.Equal(t, http.StatusInternalServerError, w.Code) + assert.Contains(t, w.Body.String(), "unsupported did:key type: bad") }) - t.Run("Fails with more than 1000 requests", func(ttt *testing.T) { + t.Run("Fails with more than 1000 requests", func(t *testing.T) { createDIDRequest := createDIDRequest // missing the data field for i := 0; i < 1000; i++ { createDIDRequest.Requests = append(createDIDRequest.Requests, createDIDRequest.Requests[0]) } - requestValue := newRequestValue(ttt, createDIDRequest) + requestValue := newRequestValue(t, createDIDRequest) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/dids/key/batch", requestValue) w := httptest.NewRecorder() params := map[string]string{"method": "key"} c := newRequestContextWithParams(w, req, params) batchDIDRouter.BatchCreateDIDs(c) - assert.Equal(ttt, http.StatusBadRequest, w.Code) - assert.Contains(ttt, w.Body.String(), "max number of requests is 100") + assert.Equal(t, http.StatusBadRequest, w.Code) + assert.Contains(t, w.Body.String(), "max number of requests is 100") }) }) } } -func createDIDWithRouter(tt *testing.T, didService *router.DIDRouter) { +func createDIDWithRouter(t *testing.T, didService *router.DIDRouter) { w := httptest.NewRecorder() createDIDRequest := router.CreateDIDByMethodRequest{KeyType: crypto.Ed25519} - requestReader := newRequestValue(tt, createDIDRequest) + requestReader := newRequestValue(t, createDIDRequest) params := map[string]string{"method": "key"} req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/dids/key", requestReader) c := newRequestContextWithParams(w, req, params) didService.CreateDIDByMethod(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var createdDID router.CreateDIDByMethodResponse err := json.NewDecoder(w.Body).Decode(&createdDID) - assert.NoError(tt, err) + assert.NoError(t, err) } diff --git a/pkg/server/server_issuance_test.go b/pkg/server/server_issuance_test.go index 58e75617c..0086e5aa2 100644 --- a/pkg/server/server_issuance_test.go +++ b/pkg/server/server_issuance_test.go @@ -32,8 +32,8 @@ func TestIssuanceRouter(t *testing.T) { for _, test := range testutil.TestDatabases { t.Run(test.Name, func(t *testing.T) { - t.Run("CreateIssuanceTemplate", func(tt *testing.T) { - issuerResp, createdSchema, manifest, r := setupAllThings(tt, test.ServiceStorage(tt)) + t.Run("CreateIssuanceTemplate", func(t *testing.T) { + issuerResp, createdSchema, manifest, r := setupAllThings(t, test.ServiceStorage(t)) for _, tc := range []struct { name string request router.CreateIssuanceTemplateRequest @@ -85,7 +85,7 @@ func TestIssuanceRouter(t *testing.T) { }, }, } { - tt.Run(tc.name, func(t *testing.T) { + t.Run(tc.name, func(t *testing.T) { value := newRequestValue(t, tc.request) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/issuancetemplates", value) w := httptest.NewRecorder() @@ -101,8 +101,8 @@ func TestIssuanceRouter(t *testing.T) { } }) - t.Run("CreateIssuanceTemplate returns error", func(tt *testing.T) { - issuerResp, createdSchema, manifest, r := setupAllThings(tt, test.ServiceStorage(tt)) + t.Run("CreateIssuanceTemplate returns error", func(t *testing.T) { + issuerResp, createdSchema, manifest, r := setupAllThings(t, test.ServiceStorage(t)) for _, tc := range []struct { name string @@ -229,21 +229,21 @@ func TestIssuanceRouter(t *testing.T) { expectedError: "field validation error", }, } { - tt.Run(tc.name, func(ttt *testing.T) { - value := newRequestValue(ttt, tc.request) + t.Run(tc.name, func(t *testing.T) { + value := newRequestValue(t, tc.request) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/issuancetemplates", value) w := httptest.NewRecorder() c := newRequestContext(w, req) r.CreateIssuanceTemplate(c) - assert.Contains(ttt, w.Body.String(), tc.expectedError) + assert.Contains(t, w.Body.String(), tc.expectedError) }) } }) - t.Run("Create, Get, Delete work as expected", func(tt *testing.T) { - issuerResp, createdSchema, manifest, r := setupAllThings(tt, test.ServiceStorage(tt)) + t.Run("Create, Get, Delete work as expected", func(t *testing.T) { + issuerResp, createdSchema, manifest, r := setupAllThings(t, test.ServiceStorage(t)) inputTemplate := issuance.Template{ CredentialManifest: manifest.Manifest.ID, @@ -273,7 +273,7 @@ func TestIssuanceRouter(t *testing.T) { c := newRequestContext(w, req) r.CreateIssuanceTemplate(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) assert.NoError(t, json.NewDecoder(w.Body).Decode(&issuanceTemplate)) if diff := cmp.Diff(inputTemplate, issuanceTemplate, cmpopts.IgnoreFields(issuance.Template{}, "ID")); diff != "" { @@ -282,84 +282,84 @@ func TestIssuanceRouter(t *testing.T) { } { - value := newRequestValue(tt, nil) + value := newRequestValue(t, nil) req := httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/issuancetemplates/"+issuanceTemplate.ID, value) w := httptest.NewRecorder() c := newRequestContextWithParams(w, req, map[string]string{"id": issuanceTemplate.ID}) r.GetIssuanceTemplate(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var getIssuanceTemplate issuance.Template assert.NoError(t, json.NewDecoder(w.Body).Decode(&getIssuanceTemplate)) if diff := cmp.Diff(issuanceTemplate, getIssuanceTemplate); diff != "" { - tt.Errorf("Template mismatch (-want +got):\n%s", diff) + t.Errorf("Template mismatch (-want +got):\n%s", diff) } } { - value := newRequestValue(tt, nil) + value := newRequestValue(t, nil) req := httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/issuancetemplates/"+issuanceTemplate.ID, value) w := httptest.NewRecorder() c := newRequestContextWithParams(w, req, map[string]string{"id": issuanceTemplate.ID}) r.DeleteIssuanceTemplate(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) } { - value := newRequestValue(tt, nil) + value := newRequestValue(t, nil) req := httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/issuancetemplates/"+issuanceTemplate.ID, value) w := httptest.NewRecorder() c := newRequestContextWithParams(w, req, map[string]string{"id": issuanceTemplate.ID}) r.GetIssuanceTemplate(c) - assert.Contains(tt, w.Body.String(), "issuance template not found") + assert.Contains(t, w.Body.String(), "issuance template not found") } }) - t.Run("GetIssuanceTemplate returns error for unknown ID", func(tt *testing.T) { - s := test.ServiceStorage(tt) - r := testIssuanceRouter(tt, s) + t.Run("GetIssuanceTemplate returns error for unknown ID", func(t *testing.T) { + s := test.ServiceStorage(t) + r := testIssuanceRouter(t, s) - value := newRequestValue(tt, nil) + value := newRequestValue(t, nil) req := httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/issuancetemplates/where-is-it", value) w := httptest.NewRecorder() c := newRequestContextWithParams(w, req, map[string]string{"id": "where-is-it"}) r.GetIssuanceTemplate(c) - assert.Contains(tt, w.Body.String(), "issuance template not found") + assert.Contains(t, w.Body.String(), "issuance template not found") }) - t.Run("ListIssuanceTemplates returns empty when there aren't templates", func(tt *testing.T) { - s := test.ServiceStorage(tt) - r := testIssuanceRouter(tt, s) + t.Run("ListIssuanceTemplates returns empty when there aren't templates", func(t *testing.T) { + s := test.ServiceStorage(t) + r := testIssuanceRouter(t, s) - value := newRequestValue(tt, nil) + value := newRequestValue(t, nil) req := httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/issuancetemplates", value) w := httptest.NewRecorder() c := newRequestContext(w, req) r.ListIssuanceTemplates(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var getIssuanceTemplate router.ListIssuanceTemplatesResponse - assert.NoError(tt, json.NewDecoder(w.Body).Decode(&getIssuanceTemplate)) - assert.Empty(tt, getIssuanceTemplate.IssuanceTemplates) + assert.NoError(t, json.NewDecoder(w.Body).Decode(&getIssuanceTemplate)) + assert.Empty(t, getIssuanceTemplate.IssuanceTemplates) }) - t.Run("ListIssuanceTemplates returns all created templates", func(tt *testing.T) { - issuerResp, createdSchema, manifest, r := setupAllThings(tt, test.ServiceStorage(tt)) + t.Run("ListIssuanceTemplates returns all created templates", func(t *testing.T) { + issuerResp, createdSchema, manifest, r := setupAllThings(t, test.ServiceStorage(t)) - createSimpleTemplate(tt, manifest, issuerResp, createdSchema, now, r) - createSimpleTemplate(tt, manifest, issuerResp, createdSchema, now, r) + createSimpleTemplate(t, manifest, issuerResp, createdSchema, now, r) + createSimpleTemplate(t, manifest, issuerResp, createdSchema, now, r) - value := newRequestValue(tt, nil) + value := newRequestValue(t, nil) req := httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/issuancetemplates", value) w := httptest.NewRecorder() c := newRequestContext(w, req) r.ListIssuanceTemplates(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var getIssuanceTemplate router.ListIssuanceTemplatesResponse - assert.NoError(tt, json.NewDecoder(w.Body).Decode(&getIssuanceTemplate)) - assert.Len(tt, getIssuanceTemplate.IssuanceTemplates, 2) + assert.NoError(t, json.NewDecoder(w.Body).Decode(&getIssuanceTemplate)) + assert.Len(t, getIssuanceTemplate.IssuanceTemplates, 2) }) }) } diff --git a/pkg/server/server_keystore_test.go b/pkg/server/server_keystore_test.go index 252d6bc53..6f5dfe520 100644 --- a/pkg/server/server_keystore_test.go +++ b/pkg/server/server_keystore_test.go @@ -21,11 +21,11 @@ func TestKeyStoreAPI(t *testing.T) { for _, test := range testutil.TestDatabases { t.Run(test.Name, func(t *testing.T) { - t.Run("Test Store Key", func(tt *testing.T) { - db := test.ServiceStorage(tt) - require.NotEmpty(tt, db) + t.Run("Test Store Key", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - keyStoreRouter, _, _ := testKeyStore(tt, db) + keyStoreRouter, _, _ := testKeyStore(t, db) w := httptest.NewRecorder() // bad key type @@ -35,20 +35,20 @@ func TestKeyStoreAPI(t *testing.T) { Controller: "me", PrivateKeyBase58: "bad", } - badRequestValue := newRequestValue(tt, badKeyStoreRequest) + badRequestValue := newRequestValue(t, badKeyStoreRequest) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/keys", badRequestValue) c := newRequestContext(w, req) keyStoreRouter.StoreKey(c) - assert.Contains(tt, w.Body.String(), "unsupported key type: bad") + assert.Contains(t, w.Body.String(), "unsupported key type: bad") // store a valid key _, privKey, err := crypto.GenerateKeyByKeyType(crypto.Ed25519) - assert.NoError(tt, err) - assert.NotEmpty(tt, privKey) + assert.NoError(t, err) + assert.NotEmpty(t, privKey) privKeyBytes, err := crypto.PrivKeyToBytes(privKey) - assert.NoError(tt, err) + assert.NoError(t, err) // good request storeKeyRequest := router.StoreKeyRequest{ @@ -57,28 +57,28 @@ func TestKeyStoreAPI(t *testing.T) { Controller: "did:test:me", PrivateKeyBase58: base58.Encode(privKeyBytes), } - requestValue := newRequestValue(tt, storeKeyRequest) + requestValue := newRequestValue(t, storeKeyRequest) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/keys", requestValue) w = httptest.NewRecorder() c = newRequestContext(w, req) keyStoreRouter.StoreKey(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) }) - t.Run("Test Get Key Details", func(tt *testing.T) { - db := test.ServiceStorage(tt) - require.NotEmpty(tt, db) + t.Run("Test Get Key Details", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - keyStoreService, _, _ := testKeyStore(tt, db) + keyStoreService, _, _ := testKeyStore(t, db) w := httptest.NewRecorder() // store a valid key pubKey, privKey, err := crypto.GenerateKeyByKeyType(crypto.Ed25519) - assert.NoError(tt, err) - assert.NotEmpty(tt, privKey) + assert.NoError(t, err) + assert.NotEmpty(t, privKey) privKeyBytes, err := crypto.PrivKeyToBytes(privKey) - assert.NoError(tt, err) + assert.NoError(t, err) // good request keyID := "did:test:me#key-2" @@ -89,31 +89,31 @@ func TestKeyStoreAPI(t *testing.T) { Controller: controller, PrivateKeyBase58: base58.Encode(privKeyBytes), } - requestValue := newRequestValue(tt, storeKeyRequest) + requestValue := newRequestValue(t, storeKeyRequest) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/keys", requestValue) c := newRequestContext(w, req) keyStoreService.StoreKey(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) // get it back w = httptest.NewRecorder() getReq := httptest.NewRequest(http.MethodGet, fmt.Sprintf("https://ssi-service.com/v1/keys/%s", keyID), nil) c = newRequestContextWithParams(w, getReq, map[string]string{"id": keyID}) keyStoreService.GetKeyDetails(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.GetKeyDetailsResponse err = json.NewDecoder(w.Body).Decode(&resp) - assert.NoError(tt, err) - assert.Equal(tt, keyID, resp.ID) - assert.Equal(tt, controller, resp.Controller) - assert.Equal(tt, crypto.Ed25519, resp.Type) + assert.NoError(t, err) + assert.Equal(t, keyID, resp.ID) + assert.Equal(t, controller, resp.Controller) + assert.Equal(t, crypto.Ed25519, resp.Type) gotPubKey, err := resp.PublicKeyJWK.ToPublicKey() - assert.NoError(tt, err) + assert.NoError(t, err) wantPubKey, err := crypto.PubKeyToBytes(pubKey) - assert.NoError(tt, err) - assert.NotEmpty(tt, wantPubKey, gotPubKey) + assert.NoError(t, err) + assert.NotEmpty(t, wantPubKey, gotPubKey) }) }) } diff --git a/pkg/server/server_manifest_test.go b/pkg/server/server_manifest_test.go index 5fe24b33b..5fe7062c0 100644 --- a/pkg/server/server_manifest_test.go +++ b/pkg/server/server_manifest_test.go @@ -37,25 +37,25 @@ import ( func TestManifestAPI(t *testing.T) { for _, test := range testutil.TestDatabases { t.Run(test.Name, func(t *testing.T) { - t.Run("Test Create Manifest", func(tt *testing.T) { - db := test.ServiceStorage(tt) - require.NotEmpty(tt, db) + t.Run("Test Create Manifest", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - keyStoreService, _ := testKeyStoreService(tt, db) - didService, _ := testDIDService(tt, db, keyStoreService, nil) - schemaService := testSchemaService(tt, db, keyStoreService, didService) - credentialService := testCredentialService(tt, db, keyStoreService, didService, schemaService) - manifestRouter, manifestService := testManifest(tt, db, keyStoreService, didService, credentialService) + keyStoreService, _ := testKeyStoreService(t, db) + didService, _ := testDIDService(t, db, keyStoreService, nil) + schemaService := testSchemaService(t, db, keyStoreService, didService) + credentialService := testCredentialService(t, db, keyStoreService, didService, schemaService) + manifestRouter, manifestService := testManifest(t, db, keyStoreService, didService, credentialService) // missing required field: Manifest var badManifestRequest router.CreateManifestRequest - badRequestValue := newRequestValue(tt, badManifestRequest) + badRequestValue := newRequestValue(t, badManifestRequest) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/manifests", badRequestValue) w := httptest.NewRecorder() c := newRequestContext(w, req) manifestRouter.CreateManifest(c) - assert.Contains(tt, w.Body.String(), "invalid create manifest request") + assert.Contains(t, w.Body.String(), "invalid create manifest request") // reset the http recorder w = httptest.NewRecorder() @@ -65,60 +65,60 @@ func TestManifestAPI(t *testing.T) { Method: didsdk.KeyMethod, KeyType: crypto.Ed25519, }) - assert.NoError(tt, err) - assert.NotEmpty(tt, issuerDID) + assert.NoError(t, err) + assert.NotEmpty(t, issuerDID) // create a schema for the creds to be issued against kid := issuerDID.DID.VerificationMethod[0].ID createdSchema, err := schemaService.CreateSchema(context.Background(), schema.CreateSchemaRequest{Issuer: issuerDID.DID.ID, FullyQualifiedVerificationMethodID: kid, Name: "license schema", Schema: getLicenseApplicationSchema()}) - assert.NoError(tt, err) - assert.NotEmpty(tt, createdSchema) + assert.NoError(t, err) + assert.NotEmpty(t, createdSchema) // good request createManifestRequest := getValidCreateManifestRequest(issuerDID.DID.ID, issuerDID.DID.VerificationMethod[0].ID, createdSchema.ID) - requestValue := newRequestValue(tt, createManifestRequest) + requestValue := newRequestValue(t, createManifestRequest) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/manifests", requestValue) c = newRequestContext(w, req) manifestRouter.CreateManifest(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.CreateManifestResponse err = json.NewDecoder(w.Body).Decode(&resp) - assert.NoError(tt, err) - assert.NotEmpty(tt, resp.Manifest) - assert.Equal(tt, resp.Manifest.Issuer.ID, issuerDID.DID.ID) + assert.NoError(t, err) + assert.NotEmpty(t, resp.Manifest) + assert.Equal(t, resp.Manifest.Issuer.ID, issuerDID.DID.ID) // create a credential manifest request manifestRequestRequest := getValidManifestRequestRequest(issuerDID, kid, resp.Manifest) - requestValue = newRequestValue(tt, manifestRequestRequest) + requestValue = newRequestValue(t, manifestRequestRequest) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/manifests/requests", requestValue) c = newRequestContext(w, req) manifestRouter.CreateRequest(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var reqResp router.CreateManifestRequestResponse err = json.NewDecoder(w.Body).Decode(&reqResp) - assert.NoError(tt, err) - assert.NotEmpty(tt, reqResp.Request) - assert.Equal(tt, "my_callback_url", reqResp.Request.CallbackURL) + assert.NoError(t, err) + assert.NotEmpty(t, reqResp.Request) + assert.Equal(t, "my_callback_url", reqResp.Request.CallbackURL) // verify the manifest verificationResponse, err := manifestService.VerifyManifest(context.Background(), manifestsvc.VerifyManifestRequest{ManifestJWT: reqResp.Request.CredentialManifestJWT}) - assert.NoError(tt, err) - assert.NotEmpty(tt, verificationResponse) - assert.True(tt, verificationResponse.Verified) + assert.NoError(t, err) + assert.NotEmpty(t, verificationResponse) + assert.True(t, verificationResponse.Verified) }) - t.Run("Test Get Manifest By ID", func(tt *testing.T) { - db := test.ServiceStorage(tt) - require.NotEmpty(tt, db) + t.Run("Test Get Manifest By ID", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - keyStoreService, _ := testKeyStoreService(tt, db) - didService, _ := testDIDService(tt, db, keyStoreService, nil) - schemaService := testSchemaService(tt, db, keyStoreService, didService) - credentialService := testCredentialService(tt, db, keyStoreService, didService, schemaService) - manifestRouter, _ := testManifest(tt, db, keyStoreService, didService, credentialService) + keyStoreService, _ := testKeyStoreService(t, db) + didService, _ := testDIDService(t, db, keyStoreService, nil) + schemaService := testSchemaService(t, db, keyStoreService, didService) + credentialService := testCredentialService(t, db, keyStoreService, didService, schemaService) + manifestRouter, _ := testManifest(t, db, keyStoreService, didService, credentialService) w := httptest.NewRecorder() @@ -126,7 +126,7 @@ func TestManifestAPI(t *testing.T) { req := httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/manifests/bad", nil) c := newRequestContext(w, req) manifestRouter.GetManifest(c) - assert.Contains(tt, w.Body.String(), "cannot get manifest without ID parameter") + assert.Contains(t, w.Body.String(), "cannot get manifest without ID parameter") // reset recorder between calls w = httptest.NewRecorder() @@ -135,7 +135,7 @@ func TestManifestAPI(t *testing.T) { req = httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/manifests/bad", nil) c = newRequestContextWithParams(w, req, map[string]string{"id": "bad"}) manifestRouter.GetManifest(c) - assert.Contains(tt, w.Body.String(), "could not get manifest with id: bad") + assert.Contains(t, w.Body.String(), "could not get manifest with id: bad") // reset recorder between calls w = httptest.NewRecorder() @@ -145,50 +145,50 @@ func TestManifestAPI(t *testing.T) { Method: didsdk.KeyMethod, KeyType: crypto.Ed25519, }) - assert.NoError(tt, err) - assert.NotEmpty(tt, issuerDID) + assert.NoError(t, err) + assert.NotEmpty(t, issuerDID) // create a schema for the creds to be issued against kid := issuerDID.DID.VerificationMethod[0].ID createdSchema, err := schemaService.CreateSchema(context.Background(), schema.CreateSchemaRequest{Issuer: issuerDID.DID.ID, FullyQualifiedVerificationMethodID: kid, Name: "license schema", Schema: getLicenseApplicationSchema()}) - assert.NoError(tt, err) - assert.NotEmpty(tt, createdSchema) + assert.NoError(t, err) + assert.NotEmpty(t, createdSchema) // good request createManifestRequest := getValidCreateManifestRequest(issuerDID.DID.ID, issuerDID.DID.VerificationMethod[0].ID, createdSchema.ID) - requestValue := newRequestValue(tt, createManifestRequest) + requestValue := newRequestValue(t, createManifestRequest) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/manifests", requestValue) c = newRequestContext(w, req) manifestRouter.CreateManifest(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.CreateManifestResponse err = json.NewDecoder(w.Body).Decode(&resp) - assert.NoError(tt, err) + assert.NoError(t, err) // get manifest by id req = httptest.NewRequest(http.MethodGet, fmt.Sprintf("https://ssi-service.com/v1/manifests/%s", resp.Manifest.ID), nil) c = newRequestContextWithParams(w, req, map[string]string{"id": resp.Manifest.ID}) manifestRouter.GetManifest(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var getManifestResp router.ListManifestResponse err = json.NewDecoder(w.Body).Decode(&getManifestResp) - assert.NoError(tt, err) - assert.NotEmpty(tt, getManifestResp) - assert.Equal(tt, resp.Manifest.ID, getManifestResp.ID) + assert.NoError(t, err) + assert.NotEmpty(t, getManifestResp) + assert.Equal(t, resp.Manifest.ID, getManifestResp.ID) }) - t.Run("Test Get Manifests", func(tt *testing.T) { - db := test.ServiceStorage(tt) - require.NotEmpty(tt, db) + t.Run("Test Get Manifests", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - keyStoreService, _ := testKeyStoreService(tt, db) - didService, _ := testDIDService(tt, db, keyStoreService, nil) - schemaService := testSchemaService(tt, db, keyStoreService, didService) - credentialService := testCredentialService(tt, db, keyStoreService, didService, schemaService) - manifestRouter, manifestService := testManifest(tt, db, keyStoreService, didService, credentialService) + keyStoreService, _ := testKeyStoreService(t, db) + didService, _ := testDIDService(t, db, keyStoreService, nil) + schemaService := testSchemaService(t, db, keyStoreService, didService) + credentialService := testCredentialService(t, db, keyStoreService, didService, schemaService) + manifestRouter, manifestService := testManifest(t, db, keyStoreService, didService, credentialService) w := httptest.NewRecorder() @@ -197,114 +197,114 @@ func TestManifestAPI(t *testing.T) { Method: didsdk.KeyMethod, KeyType: crypto.Ed25519, }) - assert.NoError(tt, err) - assert.NotEmpty(tt, issuerDID) + assert.NoError(t, err) + assert.NotEmpty(t, issuerDID) // create a schema for the creds to be issued against kid := issuerDID.DID.VerificationMethod[0].ID createdSchema, err := schemaService.CreateSchema(context.Background(), schema.CreateSchemaRequest{Issuer: issuerDID.DID.ID, FullyQualifiedVerificationMethodID: kid, Name: "license schema", Schema: getLicenseApplicationSchema()}) - assert.NoError(tt, err) - assert.NotEmpty(tt, createdSchema) + assert.NoError(t, err) + assert.NotEmpty(t, createdSchema) // good request createManifestRequest := getValidCreateManifestRequest(issuerDID.DID.ID, issuerDID.DID.VerificationMethod[0].ID, createdSchema.ID) - requestValue := newRequestValue(tt, createManifestRequest) + requestValue := newRequestValue(t, createManifestRequest) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/manifests", requestValue) c := newRequestContext(w, req) manifestRouter.CreateManifest(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.CreateManifestResponse err = json.NewDecoder(w.Body).Decode(&resp) - assert.NoError(tt, err) + assert.NoError(t, err) // list all manifests req = httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/manifests", nil) c = newRequestContext(w, req) manifestRouter.ListManifests(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var getManifestsResp router.ListManifestsResponse err = json.NewDecoder(w.Body).Decode(&getManifestsResp) - assert.NoError(tt, err) - assert.NotEmpty(tt, getManifestsResp) - assert.Len(tt, getManifestsResp.Manifests, 1) - assert.Equal(tt, resp.Manifest.ID, getManifestsResp.Manifests[0].ID) + assert.NoError(t, err) + assert.NotEmpty(t, getManifestsResp) + assert.Len(t, getManifestsResp.Manifests, 1) + assert.Equal(t, resp.Manifest.ID, getManifestsResp.Manifests[0].ID) // create a credential manifest request manifestRequestRequest := getValidManifestRequestRequest(issuerDID, kid, resp.Manifest) - requestValue = newRequestValue(tt, manifestRequestRequest) + requestValue = newRequestValue(t, manifestRequestRequest) w = httptest.NewRecorder() req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/manifests/requests", requestValue) c = newRequestContext(w, req) manifestRouter.CreateRequest(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var reqResp router.CreateManifestRequestResponse err = json.NewDecoder(w.Body).Decode(&reqResp) - assert.NoError(tt, err) - assert.NotEmpty(tt, reqResp.Request) + assert.NoError(t, err) + assert.NotEmpty(t, reqResp.Request) // list the manifest requests req = httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/manifests/requests", nil) c = newRequestContext(w, req) manifestRouter.ListRequests(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var getManifestReqsResp router.ListManifestRequestsResponse err = json.NewDecoder(w.Body).Decode(&getManifestReqsResp) - assert.NoError(tt, err) - assert.NotEmpty(tt, getManifestReqsResp) - assert.Len(tt, getManifestReqsResp.Requests, 1) - assert.Equal(tt, reqResp.Request.ID, getManifestReqsResp.Requests[0].ID) + assert.NoError(t, err) + assert.NotEmpty(t, getManifestReqsResp) + assert.Len(t, getManifestReqsResp.Requests, 1) + assert.Equal(t, reqResp.Request.ID, getManifestReqsResp.Requests[0].ID) // verify each manifest request for _, m := range getManifestReqsResp.Requests { verificationResponse, err := manifestService.VerifyManifest(context.Background(), manifestsvc.VerifyManifestRequest{ManifestJWT: m.CredentialManifestJWT}) - assert.NoError(tt, err) - assert.NotEmpty(tt, verificationResponse) - assert.True(tt, verificationResponse.Verified) + assert.NoError(t, err) + assert.NotEmpty(t, verificationResponse) + assert.True(t, verificationResponse.Verified) } }) - t.Run("Test Delete Manifest", func(tt *testing.T) { - db := test.ServiceStorage(tt) - require.NotEmpty(tt, db) + t.Run("Test Delete Manifest", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - keyStoreService, _ := testKeyStoreService(tt, db) - didService, _ := testDIDService(tt, db, keyStoreService, nil) - schemaService := testSchemaService(tt, db, keyStoreService, didService) - credentialService := testCredentialService(tt, db, keyStoreService, didService, schemaService) - manifestRouter, _ := testManifest(tt, db, keyStoreService, didService, credentialService) + keyStoreService, _ := testKeyStoreService(t, db) + didService, _ := testDIDService(t, db, keyStoreService, nil) + schemaService := testSchemaService(t, db, keyStoreService, didService) + credentialService := testCredentialService(t, db, keyStoreService, didService, schemaService) + manifestRouter, _ := testManifest(t, db, keyStoreService, didService, credentialService) // create an issuer issuerDID, err := didService.CreateDIDByMethod(context.Background(), did.CreateDIDRequest{ Method: didsdk.KeyMethod, KeyType: crypto.Ed25519, }) - assert.NoError(tt, err) - assert.NotEmpty(tt, issuerDID) + assert.NoError(t, err) + assert.NotEmpty(t, issuerDID) // create a schema for the creds to be issued against kid := issuerDID.DID.VerificationMethod[0].ID createdSchema, err := schemaService.CreateSchema(context.Background(), schema.CreateSchemaRequest{Issuer: issuerDID.DID.ID, FullyQualifiedVerificationMethodID: kid, Name: "license schema", Schema: getLicenseApplicationSchema()}) - assert.NoError(tt, err) - assert.NotEmpty(tt, createdSchema) + assert.NoError(t, err) + assert.NotEmpty(t, createdSchema) // good request createManifestRequest := getValidCreateManifestRequest(issuerDID.DID.ID, issuerDID.DID.VerificationMethod[0].ID, createdSchema.ID) - requestValue := newRequestValue(tt, createManifestRequest) + requestValue := newRequestValue(t, createManifestRequest) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/manifests", requestValue) w := httptest.NewRecorder() c := newRequestContext(w, req) manifestRouter.CreateManifest(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.CreateManifestResponse err = json.NewDecoder(w.Body).Decode(&resp) - assert.NoError(tt, err) + assert.NoError(t, err) w = httptest.NewRecorder() @@ -312,13 +312,13 @@ func TestManifestAPI(t *testing.T) { req = httptest.NewRequest(http.MethodGet, fmt.Sprintf("https://ssi-service.com/v1/manifests/%s", resp.Manifest.ID), nil) c = newRequestContextWithParams(w, req, map[string]string{"id": resp.Manifest.ID}) manifestRouter.GetManifest(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var getManifestResp router.GetCredentialResponse err = json.NewDecoder(w.Body).Decode(&getManifestResp) - assert.NoError(tt, err) - assert.NotEmpty(tt, getManifestResp) - assert.Equal(tt, resp.Manifest.ID, getManifestResp.ID) + assert.NoError(t, err) + assert.NotEmpty(t, getManifestResp) + assert.Equal(t, resp.Manifest.ID, getManifestResp.ID) w = httptest.NewRecorder() @@ -326,7 +326,7 @@ func TestManifestAPI(t *testing.T) { req = httptest.NewRequest(http.MethodDelete, fmt.Sprintf("https://ssi-service.com/v1/manifests/%s", resp.Manifest.ID), nil) c = newRequestContextWithParams(w, req, map[string]string{"id": resp.Manifest.ID}) manifestRouter.DeleteManifest(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) w = httptest.NewRecorder() @@ -334,52 +334,52 @@ func TestManifestAPI(t *testing.T) { req = httptest.NewRequest(http.MethodGet, fmt.Sprintf("https://ssi-service.com/v1/manifests/%s", resp.Manifest.ID), nil) c = newRequestContextWithParams(w, req, map[string]string{"id": resp.Manifest.ID}) manifestRouter.GetManifest(c) - assert.Contains(tt, w.Body.String(), fmt.Sprintf("could not get manifest with id: %s", resp.Manifest.ID)) + assert.Contains(t, w.Body.String(), fmt.Sprintf("could not get manifest with id: %s", resp.Manifest.ID)) }) - t.Run("Submit Application With Issuance Template", func(tt *testing.T) { - db := test.ServiceStorage(tt) - require.NotEmpty(tt, db) + t.Run("Submit Application With Issuance Template", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - keyStoreService, _ := testKeyStoreService(tt, db) - issuanceService := testIssuanceService(tt, db) - didService, _ := testDIDService(tt, db, keyStoreService, nil) - schemaService := testSchemaService(tt, db, keyStoreService, didService) - credentialService := testCredentialService(tt, db, keyStoreService, didService, schemaService) - manifestRouter, manifestSvc := testManifest(tt, db, keyStoreService, didService, credentialService) + keyStoreService, _ := testKeyStoreService(t, db) + issuanceService := testIssuanceService(t, db) + didService, _ := testDIDService(t, db, keyStoreService, nil) + schemaService := testSchemaService(t, db, keyStoreService, didService) + credentialService := testCredentialService(t, db, keyStoreService, didService, schemaService) + manifestRouter, manifestSvc := testManifest(t, db, keyStoreService, didService, credentialService) // create an issuer issuerDID, err := didService.CreateDIDByMethod(context.Background(), did.CreateDIDRequest{ Method: didsdk.KeyMethod, KeyType: crypto.Ed25519, }) - assert.NoError(tt, err) - assert.NotEmpty(tt, issuerDID) + assert.NoError(t, err) + assert.NotEmpty(t, issuerDID) // create an applicant applicantPrivKey, applicantDIDKey, err := key.GenerateDIDKey(crypto.Ed25519) - assert.NoError(tt, err) - assert.NotEmpty(tt, applicantPrivKey) - assert.NotEmpty(tt, applicantDIDKey) + assert.NoError(t, err) + assert.NotEmpty(t, applicantPrivKey) + assert.NotEmpty(t, applicantDIDKey) applicantDID, err := applicantDIDKey.Expand() - assert.NoError(tt, err) - assert.NotEmpty(tt, applicantDID) + assert.NoError(t, err) + assert.NotEmpty(t, applicantDID) // create a schema for the creds to be issued against, needed for the application kid := issuerDID.DID.VerificationMethod[0].ID licenseApplicationSchema, err := schemaService.CreateSchema( context.Background(), schema.CreateSchemaRequest{Issuer: issuerDID.DID.ID, FullyQualifiedVerificationMethodID: kid, Name: "license application schema", Schema: getLicenseApplicationSchema()}) - assert.NoError(tt, err) - assert.NotEmpty(tt, licenseApplicationSchema) + assert.NoError(t, err) + assert.NotEmpty(t, licenseApplicationSchema) // create a second schema for the creds to be issued after the application is approved licenseSchema, err := schemaService.CreateSchema( context.Background(), schema.CreateSchemaRequest{Issuer: issuerDID.DID.ID, FullyQualifiedVerificationMethodID: kid, Name: "license schema", Schema: getLicenseSchema()}) - assert.NoError(tt, err) - assert.NotEmpty(tt, licenseSchema) + assert.NoError(t, err) + assert.NotEmpty(t, licenseSchema) // issue a credential against the schema to the subject, from the issuer createdCred, err := credentialService.CreateCredential( @@ -395,25 +395,25 @@ func TestManifestAPI(t *testing.T) { "lastName": "McTest", }, }) - assert.NoError(tt, err) - assert.NotEmpty(tt, createdCred) + assert.NoError(t, err) + assert.NotEmpty(t, createdCred) // create a manifest with the schema we'll be issuing against after reviewing applications createManifestRequest := getValidCreateManifestRequest(issuerDID.DID.ID, issuerDID.DID.VerificationMethod[0].ID, licenseSchema.ID) - requestValue := newRequestValue(tt, createManifestRequest) + requestValue := newRequestValue(t, createManifestRequest) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/manifests", requestValue) w := httptest.NewRecorder() c := newRequestContext(w, req) manifestRouter.CreateManifest(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.CreateManifestResponse err = json.NewDecoder(w.Body).Decode(&resp) - assert.NoError(tt, err) + assert.NoError(t, err) m := resp.Manifest - assert.NotEmpty(tt, m) - assert.Equal(tt, m.Issuer.ID, issuerDID.DID.ID) + assert.NotEmpty(t, m) + assert.Equal(t, m.Issuer.ID, issuerDID.DID.ID) // good application request container := []credmodel.Container{{CredentialJWT: createdCred.CredentialJWT}} @@ -421,9 +421,9 @@ func TestManifestAPI(t *testing.T) { // sign application signer, err := keyaccess.NewJWKKeyAccess(applicantDID.ID, applicantDID.VerificationMethod[0].ID, applicantPrivKey) - assert.NoError(tt, err) + assert.NoError(t, err) signed, err := signer.SignJSON(applicationRequest) - assert.NoError(tt, err) + assert.NoError(t, err) expiryDateTime := time.Date(2022, 10, 31, 0, 0, 0, 0, time.UTC) mockClock := clock.NewMock() @@ -432,42 +432,42 @@ func TestManifestAPI(t *testing.T) { expiryDuration := 5 * time.Second issuanceTemplate, err := issuanceService.CreateIssuanceTemplate(context.Background(), getValidIssuanceTemplateRequest(m, issuerDID, licenseSchema.ID, expiryDateTime, expiryDuration)) - assert.NoError(tt, err) - assert.NotEmpty(tt, issuanceTemplate) + assert.NoError(t, err) + assert.NotEmpty(t, issuanceTemplate) - applicationRequestValue := newRequestValue(tt, router.SubmitApplicationRequest{ApplicationJWT: *signed}) + applicationRequestValue := newRequestValue(t, router.SubmitApplicationRequest{ApplicationJWT: *signed}) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/manifests/applications", applicationRequestValue) c = newRequestContext(w, req) manifestRouter.SubmitApplication(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var op router.Operation err = json.NewDecoder(w.Body).Decode(&op) - assert.NoError(tt, err) - assert.True(tt, op.Done) + assert.NoError(t, err) + assert.True(t, op.Done) var appResp router.SubmitApplicationResponse respData, err := json.Marshal(op.Result.Response) - assert.NoError(tt, err) + assert.NoError(t, err) err = json.Unmarshal(respData, &appResp) - assert.NoError(tt, err) - assert.Len(tt, appResp.Credentials, 2, "each output_descriptor in the definition should result in a credential") + assert.NoError(t, err) + assert.Len(t, appResp.Credentials, 2, "each output_descriptor in the definition should result in a credential") _, _, vc, err := parsing.ToCredential(appResp.Credentials[0]) - assert.NoError(tt, err) + assert.NoError(t, err) expectedSubject := credsdk.CredentialSubject{ "id": applicantDID.ID, "state": "CA", "firstName": "Tester", "lastName": "McTest", } - assert.Equal(tt, expectedSubject, vc.CredentialSubject) - assert.Equal(tt, time.Date(2022, 10, 31, 0, 0, 0, 0, time.UTC).Format(time.RFC3339), vc.ExpirationDate) - assert.True(tt, strings.HasSuffix(vc.CredentialSchema.ID, licenseSchema.ID)) - assert.Empty(tt, vc.CredentialStatus) + assert.Equal(t, expectedSubject, vc.CredentialSubject) + assert.Equal(t, time.Date(2022, 10, 31, 0, 0, 0, 0, time.UTC).Format(time.RFC3339), vc.ExpirationDate) + assert.True(t, strings.HasSuffix(vc.CredentialSchema.ID, licenseSchema.ID)) + assert.Empty(t, vc.CredentialStatus) _, _, vc2, err := parsing.ToCredential(appResp.Credentials[1]) - assert.NoError(tt, err) + assert.NoError(t, err) expectedSubject = credsdk.CredentialSubject{ "id": applicantDID.ID, "firstName": "Tester", @@ -481,67 +481,67 @@ func TestManifestAPI(t *testing.T) { }, }, } - assert.Equal(tt, expectedSubject, vc2.CredentialSubject) - assert.Equal(tt, + assert.Equal(t, expectedSubject, vc2.CredentialSubject) + assert.Equal(t, time.Date(2022, 10, 31, 0, 0, 5, 0, time.UTC).Format(time.RFC3339), vc2.ExpirationDate, ) - assert.True(tt, strings.HasSuffix(vc2.CredentialSchema.ID, licenseSchema.ID)) - assert.NotEmpty(tt, vc2.CredentialStatus) + assert.True(t, strings.HasSuffix(vc2.CredentialSchema.ID, licenseSchema.ID)) + assert.NotEmpty(t, vc2.CredentialStatus) }) - t.Run("Test Submit Application with multiple outputs and overrides", func(tt *testing.T) { - db := test.ServiceStorage(tt) - require.NotEmpty(tt, db) + t.Run("Test Submit Application with multiple outputs and overrides", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - keyStoreService, _ := testKeyStoreService(tt, db) - didService, _ := testDIDService(tt, db, keyStoreService, nil) - schemaService := testSchemaService(tt, db, keyStoreService, didService) - credentialService := testCredentialService(tt, db, keyStoreService, didService, schemaService) - manifestRouter, _ := testManifest(tt, db, keyStoreService, didService, credentialService) + keyStoreService, _ := testKeyStoreService(t, db) + didService, _ := testDIDService(t, db, keyStoreService, nil) + schemaService := testSchemaService(t, db, keyStoreService, didService) + credentialService := testCredentialService(t, db, keyStoreService, didService, schemaService) + manifestRouter, _ := testManifest(t, db, keyStoreService, didService, credentialService) // missing required field: Application badManifestRequest := router.SubmitApplicationRequest{ApplicationJWT: "bad"} - badRequestValue := newRequestValue(tt, badManifestRequest) + badRequestValue := newRequestValue(t, badManifestRequest) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/manifests/applications", badRequestValue) w := httptest.NewRecorder() c := newRequestContext(w, req) manifestRouter.SubmitApplication(c) - assert.Contains(tt, w.Body.String(), "invalid submit application request") + assert.Contains(t, w.Body.String(), "invalid submit application request") // create an issuer issuerDID, err := didService.CreateDIDByMethod(context.Background(), did.CreateDIDRequest{ Method: didsdk.KeyMethod, KeyType: crypto.Ed25519, }) - assert.NoError(tt, err) - assert.NotEmpty(tt, issuerDID) + assert.NoError(t, err) + assert.NotEmpty(t, issuerDID) // create an applicant applicantPrivKey, applicantDIDKey, err := key.GenerateDIDKey(crypto.Ed25519) - assert.NoError(tt, err) - assert.NotEmpty(tt, applicantPrivKey) - assert.NotEmpty(tt, applicantDIDKey) + assert.NoError(t, err) + assert.NotEmpty(t, applicantPrivKey) + assert.NotEmpty(t, applicantDIDKey) applicantDID, err := applicantDIDKey.Expand() - assert.NoError(tt, err) - assert.NotEmpty(tt, applicantDID) + assert.NoError(t, err) + assert.NotEmpty(t, applicantDID) // create a schema for the creds to be issued against, needed for the application kid := issuerDID.DID.VerificationMethod[0].ID licenseApplicationSchema, err := schemaService.CreateSchema( context.Background(), schema.CreateSchemaRequest{Issuer: issuerDID.DID.ID, FullyQualifiedVerificationMethodID: kid, Name: "license application schema", Schema: getLicenseApplicationSchema()}) - assert.NoError(tt, err) - assert.NotEmpty(tt, licenseApplicationSchema) + assert.NoError(t, err) + assert.NotEmpty(t, licenseApplicationSchema) // create a second schema for the creds to be issued after the application is approved licenseSchema, err := schemaService.CreateSchema( context.Background(), schema.CreateSchemaRequest{Issuer: issuerDID.DID.ID, FullyQualifiedVerificationMethodID: kid, Name: "license schema", Schema: getLicenseSchema()}) - assert.NoError(tt, err) - assert.NotEmpty(tt, licenseSchema) + assert.NoError(t, err) + assert.NotEmpty(t, licenseSchema) // issue a credential against the schema to the subject, from the issuer createdCred, err := credentialService.CreateCredential(context.Background(), credential.CreateCredentialRequest{ @@ -551,25 +551,25 @@ func TestManifestAPI(t *testing.T) { SchemaID: licenseApplicationSchema.ID, Data: map[string]any{"licenseType": "Class D"}, }) - assert.NoError(tt, err) - assert.NotEmpty(tt, createdCred) + assert.NoError(t, err) + assert.NotEmpty(t, createdCred) // good request to create a manifest createManifestRequest := getValidCreateManifestRequest(issuerDID.DID.ID, issuerDID.DID.VerificationMethod[0].ID, licenseSchema.ID) w = httptest.NewRecorder() - requestValue := newRequestValue(tt, createManifestRequest) + requestValue := newRequestValue(t, createManifestRequest) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/manifests", requestValue) c = newRequestContext(w, req) manifestRouter.CreateManifest(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.CreateManifestResponse err = json.NewDecoder(w.Body).Decode(&resp) - assert.NoError(tt, err) + assert.NoError(t, err) m := resp.Manifest - assert.NotEmpty(tt, m) - assert.Equal(tt, m.Issuer.ID, issuerDID.DID.ID) + assert.NotEmpty(t, m) + assert.Equal(t, m.Issuer.ID, issuerDID.DID.ID) // good application request container := []credmodel.Container{{CredentialJWT: createdCred.CredentialJWT}} @@ -577,28 +577,28 @@ func TestManifestAPI(t *testing.T) { // sign application signer, err := keyaccess.NewJWKKeyAccess(applicantDID.ID, applicantDID.VerificationMethod[0].ID, applicantPrivKey) - assert.NoError(tt, err) + assert.NoError(t, err) signed, err := signer.SignJSON(applicationRequest) - assert.NoError(tt, err) + assert.NoError(t, err) w = httptest.NewRecorder() - applicationRequestValue := newRequestValue(tt, router.SubmitApplicationRequest{ApplicationJWT: *signed}) + applicationRequestValue := newRequestValue(t, router.SubmitApplicationRequest{ApplicationJWT: *signed}) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/manifests/applications", applicationRequestValue) c = newRequestContext(w, req) manifestRouter.SubmitApplication(c) - assert.NoError(tt, err) + assert.NoError(t, err) var op router.Operation err = json.NewDecoder(w.Body).Decode(&op) - assert.NoError(tt, err) + assert.NoError(t, err) - assert.False(tt, op.Done) - assert.Contains(tt, op.ID, "credentials/responses/") + assert.False(t, op.Done) + assert.Contains(t, op.ID, "credentials/responses/") // review application expireAt := time.Date(2025, 10, 32, 0, 0, 0, 0, time.UTC) - reviewApplicationRequestValue := newRequestValue(tt, router.ReviewApplicationRequest{ + reviewApplicationRequestValue := newRequestValue(t, router.ReviewApplicationRequest{ Approved: true, Reason: "I'm the almighty approver", CredentialOverrides: map[string]manifestsvc.CredentialOverride{ @@ -628,80 +628,80 @@ func TestManifestAPI(t *testing.T) { req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/manifests/applications/"+applicationID+"/review", reviewApplicationRequestValue) c = newRequestContextWithParams(w, req, map[string]string{"id": applicationID}) manifestRouter.ReviewApplication(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var appResp router.SubmitApplicationResponse err = json.NewDecoder(w.Body).Decode(&appResp) - assert.NoError(tt, err) + assert.NoError(t, err) - assert.NotEmpty(tt, appResp.Response) - assert.Equal(tt, resp.Manifest.ID, appResp.Response.ManifestID) - assert.NotEmpty(tt, appResp.Response.Fulfillment) - assert.Len(tt, appResp.Response.Fulfillment.DescriptorMap, 2) - assert.Len(tt, appResp.Credentials, 2) - assert.Empty(tt, appResp.Response.Denial) + assert.NotEmpty(t, appResp.Response) + assert.Equal(t, resp.Manifest.ID, appResp.Response.ManifestID) + assert.NotEmpty(t, appResp.Response.Fulfillment) + assert.Len(t, appResp.Response.Fulfillment.DescriptorMap, 2) + assert.Len(t, appResp.Credentials, 2) + assert.Empty(t, appResp.Response.Denial) _, _, vc, err := parsing.ToCredential(appResp.Credentials[0]) - assert.NoError(tt, err) - assert.Equal(tt, credsdk.CredentialSubject{ + assert.NoError(t, err) + assert.Equal(t, credsdk.CredentialSubject{ "id": applicantDID.ID, "firstName": "John", "lastName": "Doe", "state": "CA", "looks": "pretty darn handsome", }, vc.CredentialSubject) - assert.Equal(tt, expireAt.Format(time.RFC3339), vc.ExpirationDate) - assert.NotEmpty(tt, vc.CredentialStatus) - assert.True(tt, strings.HasSuffix(vc.CredentialSchema.ID, licenseSchema.ID)) + assert.Equal(t, expireAt.Format(time.RFC3339), vc.ExpirationDate) + assert.NotEmpty(t, vc.CredentialStatus) + assert.True(t, strings.HasSuffix(vc.CredentialSchema.ID, licenseSchema.ID)) }) - t.Run("Test Denied Application", func(tt *testing.T) { - db := test.ServiceStorage(tt) - require.NotEmpty(tt, db) + t.Run("Test Denied Application", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - keyStoreService, _ := testKeyStoreService(tt, db) - didService, _ := testDIDService(tt, db, keyStoreService, nil) - schemaService := testSchemaService(tt, db, keyStoreService, didService) - credentialService := testCredentialService(tt, db, keyStoreService, didService, schemaService) - manifestRouter, _ := testManifest(tt, db, keyStoreService, didService, credentialService) + keyStoreService, _ := testKeyStoreService(t, db) + didService, _ := testDIDService(t, db, keyStoreService, nil) + schemaService := testSchemaService(t, db, keyStoreService, didService) + credentialService := testCredentialService(t, db, keyStoreService, didService, schemaService) + manifestRouter, _ := testManifest(t, db, keyStoreService, didService, credentialService) // missing required field: Application badManifestRequest := router.SubmitApplicationRequest{ ApplicationJWT: "bad", } - badRequestValue := newRequestValue(tt, badManifestRequest) + badRequestValue := newRequestValue(t, badManifestRequest) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/manifests/applications", badRequestValue) w := httptest.NewRecorder() c := newRequestContext(w, req) manifestRouter.SubmitApplication(c) - assert.Contains(tt, w.Body.String(), "invalid submit application request") + assert.Contains(t, w.Body.String(), "invalid submit application request") // create an issuer issuerDID, err := didService.CreateDIDByMethod(context.Background(), did.CreateDIDRequest{ Method: didsdk.KeyMethod, KeyType: crypto.Ed25519, }) - assert.NoError(tt, err) - assert.NotEmpty(tt, issuerDID) + assert.NoError(t, err) + assert.NotEmpty(t, issuerDID) // create an applicant applicantPrivKey, applicantDIDKey, err := key.GenerateDIDKey(crypto.Ed25519) - assert.NoError(tt, err) - assert.NotEmpty(tt, applicantPrivKey) - assert.NotEmpty(tt, applicantDIDKey) + assert.NoError(t, err) + assert.NotEmpty(t, applicantPrivKey) + assert.NotEmpty(t, applicantDIDKey) applicantDID, err := applicantDIDKey.Expand() - assert.NoError(tt, err) - assert.NotEmpty(tt, applicantDID) + assert.NoError(t, err) + assert.NotEmpty(t, applicantDID) // create a schema for the creds to be issued against kid := issuerDID.DID.VerificationMethod[0].ID licenseApplicationSchema, err := schemaService.CreateSchema(context.Background(), schema.CreateSchemaRequest{Issuer: issuerDID.DID.ID, FullyQualifiedVerificationMethodID: kid, Name: "license application schema", Schema: getLicenseApplicationSchema()}) - assert.NoError(tt, err) - assert.NotEmpty(tt, licenseApplicationSchema) + assert.NoError(t, err) + assert.NotEmpty(t, licenseApplicationSchema) // issue a credential against the schema to the subject, from the issuer createdCred, err := credentialService.CreateCredential(context.Background(), credential.CreateCredentialRequest{ @@ -711,27 +711,27 @@ func TestManifestAPI(t *testing.T) { SchemaID: licenseApplicationSchema.ID, Data: map[string]any{"licenseType": "Class D"}, }) - assert.NoError(tt, err) - assert.NotEmpty(tt, createdCred) + assert.NoError(t, err) + assert.NotEmpty(t, createdCred) w = httptest.NewRecorder() // good request createManifestRequest := getValidCreateManifestRequest(issuerDID.DID.ID, issuerDID.DID.VerificationMethod[0].ID, licenseApplicationSchema.ID) - requestValue := newRequestValue(tt, createManifestRequest) + requestValue := newRequestValue(t, createManifestRequest) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/manifests", requestValue) c = newRequestContext(w, req) manifestRouter.CreateManifest(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.CreateManifestResponse err = json.NewDecoder(w.Body).Decode(&resp) - assert.NoError(tt, err) + assert.NoError(t, err) m := resp.Manifest - assert.NotEmpty(tt, m) - assert.Equal(tt, m.Issuer.ID, issuerDID.DID.ID) + assert.NotEmpty(t, m) + assert.Equal(t, m.Issuer.ID, issuerDID.DID.ID) // good application request container := []credmodel.Container{{CredentialJWT: createdCred.CredentialJWT}} @@ -743,34 +743,34 @@ func TestManifestAPI(t *testing.T) { // sign application signer, err := keyaccess.NewJWKKeyAccess(applicantDID.ID, applicantDID.VerificationMethod[0].ID, applicantPrivKey) - assert.NoError(tt, err) + assert.NoError(t, err) signed, err := signer.SignJSON(applicationRequest) - assert.NoError(tt, err) + assert.NoError(t, err) w = httptest.NewRecorder() - applicationRequestValue := newRequestValue(tt, router.SubmitApplicationRequest{ApplicationJWT: *signed}) + applicationRequestValue := newRequestValue(t, router.SubmitApplicationRequest{ApplicationJWT: *signed}) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/manifests/applications", applicationRequestValue) c = newRequestContext(w, req) manifestRouter.SubmitApplication(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var op router.Operation err = json.NewDecoder(w.Body).Decode(&op) - assert.NoError(tt, err) + assert.NoError(t, err) var appResp router.SubmitApplicationResponse respData, err := json.Marshal(op.Result.Response) - assert.NoError(tt, err) + assert.NoError(t, err) err = json.Unmarshal(respData, &appResp) - assert.NoError(tt, err) + assert.NoError(t, err) - assert.NotEmpty(tt, appResp.Response) - assert.Equal(tt, resp.Manifest.ID, appResp.Response.ManifestID) - assert.NotEmpty(tt, appResp.Response.Denial) - assert.Contains(tt, appResp.Response.Denial.Reason, "no descriptors provided for application") - assert.Len(tt, appResp.Response.Denial.InputDescriptors, 0) + assert.NotEmpty(t, appResp.Response) + assert.Equal(t, resp.Manifest.ID, appResp.Response.ManifestID) + assert.NotEmpty(t, appResp.Response.Denial) + assert.Contains(t, appResp.Response.Denial.Reason, "no descriptors provided for application") + assert.Len(t, appResp.Response.Denial.InputDescriptors, 0) // submit it again, with an unfulfilled descriptor savedSubmission.DescriptorMap[0].ID = "bad" @@ -780,46 +780,46 @@ func TestManifestAPI(t *testing.T) { // sign application signed, err = signer.SignJSON(applicationRequest) - assert.NoError(tt, err) + assert.NoError(t, err) - applicationRequestValue = newRequestValue(tt, router.SubmitApplicationRequest{ApplicationJWT: *signed}) + applicationRequestValue = newRequestValue(t, router.SubmitApplicationRequest{ApplicationJWT: *signed}) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/manifests/applications", applicationRequestValue) c = newRequestContext(w, req) manifestRouter.SubmitApplication(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) err = json.NewDecoder(w.Body).Decode(&op) - assert.NoError(tt, err) + assert.NoError(t, err) respData, err = json.Marshal(op.Result.Response) - assert.NoError(tt, err) + assert.NoError(t, err) err = json.Unmarshal(respData, &appResp) - assert.NoError(tt, err) - - assert.NotEmpty(tt, appResp.Response) - assert.Equal(tt, resp.Manifest.ID, appResp.Response.ManifestID) - assert.NotEmpty(tt, appResp.Response.Denial) - assert.Contains(tt, appResp.Response.Denial.Reason, "unfilled input descriptor(s): license-type: no submission descriptor found for input descriptor") - assert.Len(tt, appResp.Response.Denial.InputDescriptors, 1) - assert.Equal(tt, appResp.Response.Denial.InputDescriptors[0], "license-type") + assert.NoError(t, err) + + assert.NotEmpty(t, appResp.Response) + assert.Equal(t, resp.Manifest.ID, appResp.Response.ManifestID) + assert.NotEmpty(t, appResp.Response.Denial) + assert.Contains(t, appResp.Response.Denial.Reason, "unfilled input descriptor(s): license-type: no submission descriptor found for input descriptor") + assert.Len(t, appResp.Response.Denial.InputDescriptors, 1) + assert.Equal(t, appResp.Response.Denial.InputDescriptors[0], "license-type") }) - t.Run("Test Get Application By ID and Get Applications", func(tt *testing.T) { - db := test.ServiceStorage(tt) - require.NotEmpty(tt, db) + t.Run("Test Get Application By ID and Get Applications", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - keyStoreService, _ := testKeyStoreService(tt, db) - didService, _ := testDIDService(tt, db, keyStoreService, nil) - schemaService := testSchemaService(tt, db, keyStoreService, didService) - credentialService := testCredentialService(tt, db, keyStoreService, didService, schemaService) - manifestRouter, _ := testManifest(tt, db, keyStoreService, didService, credentialService) + keyStoreService, _ := testKeyStoreService(t, db) + didService, _ := testDIDService(t, db, keyStoreService, nil) + schemaService := testSchemaService(t, db, keyStoreService, didService) + credentialService := testCredentialService(t, db, keyStoreService, didService, schemaService) + manifestRouter, _ := testManifest(t, db, keyStoreService, didService, credentialService) w := httptest.NewRecorder() // get a application that doesn't exit req := httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/manifests/applications/bad", nil) c := newRequestContext(w, req) manifestRouter.GetApplication(c) - assert.Contains(tt, w.Body.String(), "cannot get application without ID parameter") + assert.Contains(t, w.Body.String(), "cannot get application without ID parameter") // reset recorder between calls w = httptest.NewRecorder() @@ -829,31 +829,31 @@ func TestManifestAPI(t *testing.T) { Method: didsdk.KeyMethod, KeyType: crypto.Ed25519, }) - assert.NoError(tt, err) - assert.NotEmpty(tt, issuerDID) + assert.NoError(t, err) + assert.NotEmpty(t, issuerDID) // create an applicant applicantPrivKey, applicantDIDKey, err := key.GenerateDIDKey(crypto.Ed25519) - assert.NoError(tt, err) - assert.NotEmpty(tt, applicantPrivKey) - assert.NotEmpty(tt, applicantDIDKey) + assert.NoError(t, err) + assert.NotEmpty(t, applicantPrivKey) + assert.NotEmpty(t, applicantDIDKey) applicantDID, err := applicantDIDKey.Expand() - assert.NoError(tt, err) - assert.NotEmpty(tt, applicantDID) + assert.NoError(t, err) + assert.NotEmpty(t, applicantDID) // create a schema for the creds to be issued against kid := issuerDID.DID.VerificationMethod[0].ID licenseApplicationSchema, err := schemaService.CreateSchema(context.Background(), schema.CreateSchemaRequest{Issuer: issuerDID.DID.ID, FullyQualifiedVerificationMethodID: kid, Name: "license application schema", Schema: getLicenseApplicationSchema()}) - assert.NoError(tt, err) - assert.NotEmpty(tt, licenseApplicationSchema) + assert.NoError(t, err) + assert.NotEmpty(t, licenseApplicationSchema) licenseSchema, err := schemaService.CreateSchema( context.Background(), schema.CreateSchemaRequest{Issuer: issuerDID.DID.ID, FullyQualifiedVerificationMethodID: kid, Name: "license schema", Schema: getLicenseSchema()}) - assert.NoError(tt, err) - assert.NotEmpty(tt, licenseSchema) + assert.NoError(t, err) + assert.NotEmpty(t, licenseSchema) // issue a credential against the schema to the subject, from the issuer createdCred, err := credentialService.CreateCredential(context.Background(), credential.CreateCredentialRequest{ Issuer: issuerDID.DID.ID, @@ -862,25 +862,25 @@ func TestManifestAPI(t *testing.T) { SchemaID: licenseApplicationSchema.ID, Data: map[string]any{"licenseType": "Class D"}, }) - assert.NoError(tt, err) - assert.NotEmpty(tt, createdCred) + assert.NoError(t, err) + assert.NotEmpty(t, createdCred) // good request createManifestRequest := getValidCreateManifestRequest(issuerDID.DID.ID, issuerDID.DID.VerificationMethod[0].ID, licenseSchema.ID) - requestValue := newRequestValue(tt, createManifestRequest) + requestValue := newRequestValue(t, createManifestRequest) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/manifests", requestValue) c = newRequestContext(w, req) manifestRouter.CreateManifest(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.CreateManifestResponse err = json.NewDecoder(w.Body).Decode(&resp) - assert.NoError(tt, err) + assert.NoError(t, err) m := resp.Manifest - assert.NotEmpty(tt, m) - assert.Equal(tt, m.Issuer.ID, issuerDID.DID.ID) + assert.NotEmpty(t, m) + assert.Equal(t, m.Issuer.ID, issuerDID.DID.ID) // good application request container := []credmodel.Container{{CredentialJWT: createdCred.CredentialJWT}} @@ -888,22 +888,22 @@ func TestManifestAPI(t *testing.T) { // sign application signer, err := keyaccess.NewJWKKeyAccess(applicantDID.ID, applicantDID.VerificationMethod[0].ID, applicantPrivKey) - assert.NoError(tt, err) + assert.NoError(t, err) signed, err := signer.SignJSON(applicationRequest) - assert.NoError(tt, err) + assert.NoError(t, err) - applicationRequestValue := newRequestValue(tt, router.SubmitApplicationRequest{ApplicationJWT: *signed}) + applicationRequestValue := newRequestValue(t, router.SubmitApplicationRequest{ApplicationJWT: *signed}) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/manifests/applications", applicationRequestValue) c = newRequestContext(w, req) manifestRouter.SubmitApplication(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var op router.Operation err = json.NewDecoder(w.Body).Decode(&op) - assert.NoError(tt, err) + assert.NoError(t, err) // review application - reviewApplicationRequestValue := newRequestValue(tt, router.ReviewApplicationRequest{ + reviewApplicationRequestValue := newRequestValue(t, router.ReviewApplicationRequest{ Approved: true, Reason: "I'm the almighty approver", CredentialOverrides: map[string]manifestsvc.CredentialOverride{ @@ -929,75 +929,75 @@ func TestManifestAPI(t *testing.T) { req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/manifests/applications/"+applicationID+"/review", reviewApplicationRequestValue) c = newRequestContextWithParams(w, req, map[string]string{"id": applicationID}) manifestRouter.ReviewApplication(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var appResp router.SubmitApplicationResponse err = json.NewDecoder(w.Body).Decode(&appResp) - assert.NoError(tt, err) + assert.NoError(t, err) - assert.NotEmpty(tt, appResp.Response.Fulfillment) - assert.Empty(tt, appResp.Response.Denial) + assert.NotEmpty(t, appResp.Response.Fulfillment) + assert.Empty(t, appResp.Response.Denial) // get response by id req = httptest.NewRequest(http.MethodGet, fmt.Sprintf("https://ssi-service.com/v1/manifests/responses/%s", appResp.Response.ID), nil) c = newRequestContextWithParams(w, req, map[string]string{"id": appResp.Response.ID}) manifestRouter.GetResponse(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var getResponseResponse router.GetResponseResponse err = json.NewDecoder(w.Body).Decode(&getResponseResponse) - assert.NoError(tt, err) - assert.NotEmpty(tt, getResponseResponse) - assert.Equal(tt, appResp.Response.ID, getResponseResponse.Response.ID) + assert.NoError(t, err) + assert.NotEmpty(t, getResponseResponse) + assert.Equal(t, appResp.Response.ID, getResponseResponse.Response.ID) // get all responses req = httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/manifests/responses", nil) c = newRequestContext(w, req) manifestRouter.ListResponses(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var getResponsesResp router.ListResponsesResponse err = json.NewDecoder(w.Body).Decode(&getResponsesResp) - assert.NoError(tt, err) - assert.NotEmpty(tt, getResponsesResp) + assert.NoError(t, err) + assert.NotEmpty(t, getResponsesResp) - assert.Len(tt, getResponsesResp.Responses, 1) + assert.Len(t, getResponsesResp.Responses, 1) // get all applications req = httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/manifests/applications", applicationRequestValue) c = newRequestContext(w, req) manifestRouter.ListApplications(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var getApplicationsResp router.ListApplicationsResponse err = json.NewDecoder(w.Body).Decode(&getApplicationsResp) - assert.NoError(tt, err) - assert.NotEmpty(tt, getApplicationsResp) + assert.NoError(t, err) + assert.NotEmpty(t, getApplicationsResp) - assert.Len(tt, getApplicationsResp.Applications, 1) + assert.Len(t, getApplicationsResp.Applications, 1) // get application by id req = httptest.NewRequest(http.MethodGet, fmt.Sprintf("https://ssi-service.com/v1/manifests/applications/%s", getApplicationsResp.Applications[0].ID), nil) c = newRequestContextWithParams(w, req, map[string]string{"id": getApplicationsResp.Applications[0].ID}) manifestRouter.GetApplication(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var getApplicationResponse router.GetApplicationResponse err = json.NewDecoder(w.Body).Decode(&getApplicationResponse) - assert.NoError(tt, err) - assert.NotEmpty(tt, getApplicationResponse) - assert.Equal(tt, getApplicationsResp.Applications[0].ID, getApplicationResponse.ID) + assert.NoError(t, err) + assert.NotEmpty(t, getApplicationResponse) + assert.Equal(t, getApplicationsResp.Applications[0].ID, getApplicationResponse.ID) }) - t.Run("Test Delete Application", func(tt *testing.T) { - db := test.ServiceStorage(tt) - require.NotEmpty(tt, db) + t.Run("Test Delete Application", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - keyStoreService, _ := testKeyStoreService(tt, db) - didService, _ := testDIDService(tt, db, keyStoreService, nil) - schemaService := testSchemaService(tt, db, keyStoreService, didService) - credentialService := testCredentialService(tt, db, keyStoreService, didService, schemaService) - manifestRouter, _ := testManifest(tt, db, keyStoreService, didService, credentialService) + keyStoreService, _ := testKeyStoreService(t, db) + didService, _ := testDIDService(t, db, keyStoreService, nil) + schemaService := testSchemaService(t, db, keyStoreService, didService) + credentialService := testCredentialService(t, db, keyStoreService, didService, schemaService) + manifestRouter, _ := testManifest(t, db, keyStoreService, didService, credentialService) w := httptest.NewRecorder() @@ -1006,25 +1006,25 @@ func TestManifestAPI(t *testing.T) { Method: didsdk.KeyMethod, KeyType: crypto.Ed25519, }) - assert.NoError(tt, err) - assert.NotEmpty(tt, issuerDID) + assert.NoError(t, err) + assert.NotEmpty(t, issuerDID) // create an applicant applicantPrivKey, applicantDIDKey, err := key.GenerateDIDKey(crypto.Ed25519) - assert.NoError(tt, err) - assert.NotEmpty(tt, applicantPrivKey) - assert.NotEmpty(tt, applicantDIDKey) + assert.NoError(t, err) + assert.NotEmpty(t, applicantPrivKey) + assert.NotEmpty(t, applicantDIDKey) applicantDID, err := applicantDIDKey.Expand() - assert.NoError(tt, err) - assert.NotEmpty(tt, applicantDID) + assert.NoError(t, err) + assert.NotEmpty(t, applicantDID) // create a schema for the creds to be issued against kid := issuerDID.DID.VerificationMethod[0].ID createdSchema, err := schemaService.CreateSchema(context.Background(), schema.CreateSchemaRequest{Issuer: issuerDID.DID.ID, FullyQualifiedVerificationMethodID: kid, Name: "license schema", Schema: getLicenseApplicationSchema()}) - assert.NoError(tt, err) - assert.NotEmpty(tt, createdSchema) + assert.NoError(t, err) + assert.NotEmpty(t, createdSchema) // issue a credential against the schema to the subject, from the issuer createdCred, err := credentialService.CreateCredential(context.Background(), credential.CreateCredentialRequest{ @@ -1034,25 +1034,25 @@ func TestManifestAPI(t *testing.T) { SchemaID: createdSchema.ID, Data: map[string]any{"licenseType": "WA-DL-CLASS-A"}, }) - assert.NoError(tt, err) - assert.NotEmpty(tt, createdCred) + assert.NoError(t, err) + assert.NotEmpty(t, createdCred) // good request createManifestRequest := getValidCreateManifestRequest(issuerDID.DID.ID, issuerDID.DID.VerificationMethod[0].ID, createdSchema.ID) - requestValue := newRequestValue(tt, createManifestRequest) + requestValue := newRequestValue(t, createManifestRequest) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/manifests", requestValue) c := newRequestContext(w, req) manifestRouter.CreateManifest(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.CreateManifestResponse err = json.NewDecoder(w.Body).Decode(&resp) - assert.NoError(tt, err) + assert.NoError(t, err) m := resp.Manifest - assert.NotEmpty(tt, m) - assert.Equal(tt, m.Issuer.ID, issuerDID.DID.ID) + assert.NotEmpty(t, m) + assert.Equal(t, m.Issuer.ID, issuerDID.DID.ID) // good application request container := []credmodel.Container{{CredentialJWT: createdCred.CredentialJWT}} @@ -1060,49 +1060,49 @@ func TestManifestAPI(t *testing.T) { // sign application signer, err := keyaccess.NewJWKKeyAccess(applicantDID.ID, applicantDID.VerificationMethod[0].ID, applicantPrivKey) - assert.NoError(tt, err) + assert.NoError(t, err) signed, err := signer.SignJSON(applicationRequest) - assert.NoError(tt, err) + assert.NoError(t, err) - applicationRequestValue := newRequestValue(tt, router.SubmitApplicationRequest{ApplicationJWT: *signed}) + applicationRequestValue := newRequestValue(t, router.SubmitApplicationRequest{ApplicationJWT: *signed}) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/manifests/applications", applicationRequestValue) c = newRequestContext(w, req) manifestRouter.SubmitApplication(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var appResp router.SubmitApplicationResponse err = json.NewDecoder(w.Body).Decode(&appResp) - assert.NoError(tt, err) + assert.NoError(t, err) // get all applications req = httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/manifests/applications", applicationRequestValue) c = newRequestContext(w, req) manifestRouter.ListApplications(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var getApplicationsResp router.ListApplicationsResponse err = json.NewDecoder(w.Body).Decode(&getApplicationsResp) - assert.NoError(tt, err) - assert.NotEmpty(tt, getApplicationsResp) - assert.Len(tt, getApplicationsResp.Applications, 1) + assert.NoError(t, err) + assert.NotEmpty(t, getApplicationsResp) + assert.Len(t, getApplicationsResp.Applications, 1) // get the application req = httptest.NewRequest(http.MethodGet, fmt.Sprintf("https://ssi-service.com/v1/manifests/applications/%s", getApplicationsResp.Applications[0].ID), nil) c = newRequestContextWithParams(w, req, map[string]string{"id": getApplicationsResp.Applications[0].ID}) manifestRouter.GetApplication(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var getApplicationResp router.GetApplicationResponse err = json.NewDecoder(w.Body).Decode(&getApplicationResp) - assert.NoError(tt, err) - assert.NotEmpty(tt, getApplicationResp) - assert.Equal(tt, resp.Manifest.ID, getApplicationResp.Application.ManifestID) + assert.NoError(t, err) + assert.NotEmpty(t, getApplicationResp) + assert.Equal(t, resp.Manifest.ID, getApplicationResp.Application.ManifestID) // delete the application req = httptest.NewRequest(http.MethodDelete, fmt.Sprintf("https://ssi-service.com/v1/manifests/applications/%s", getApplicationResp.Application.ID), nil) c = newRequestContextWithParams(w, req, map[string]string{"id": getApplicationsResp.Applications[0].ID}) manifestRouter.DeleteApplication(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) w = httptest.NewRecorder() @@ -1110,7 +1110,7 @@ func TestManifestAPI(t *testing.T) { req = httptest.NewRequest(http.MethodGet, fmt.Sprintf("https://ssi-service.com/v1/manifests/applications/%s", appResp.Response.ID), nil) c = newRequestContextWithParams(w, req, map[string]string{"id": getApplicationsResp.Applications[0].ID}) manifestRouter.GetApplication(c) - assert.Contains(tt, w.Body.String(), fmt.Sprintf("could not get application with id: %s", appResp.Response.ID)) + assert.Contains(t, w.Body.String(), fmt.Sprintf("could not get application with id: %s", appResp.Response.ID)) }) }) } diff --git a/pkg/server/server_operation_test.go b/pkg/server/server_operation_test.go index b922caa82..f8adc7a80 100644 --- a/pkg/server/server_operation_test.go +++ b/pkg/server/server_operation_test.go @@ -24,13 +24,13 @@ import ( func TestOperationsAPI(t *testing.T) { for _, test := range testutil.TestDatabases { t.Run(test.Name, func(t *testing.T) { - t.Run("Marks operation as done after reviewing submission", func(tt *testing.T) { - s := test.ServiceStorage(tt) - pRouter, didService := setupPresentationRouter(tt, s) - authorDID := createDID(tt, didService) - opRouter := setupOperationsRouter(tt, s) + t.Run("Marks operation as done after reviewing submission", func(t *testing.T) { + s := test.ServiceStorage(t) + pRouter, didService := setupPresentationRouter(t, s) + authorDID := createDID(t, didService) + opRouter := setupOperationsRouter(t, s) - holderSigner, holderDID := getSigner(tt) + holderSigner, holderDID := getSigner(t) definition := createPresentationDefinition(t, pRouter) submissionOp := createSubmission(t, pRouter, definition.PresentationDefinition.ID, authorDID.DID.ID, VerifiableCredential(), holderDID, holderSigner) sub := reviewSubmission(t, pRouter, opstorage.StatusObjectID(submissionOp.ID)) @@ -41,30 +41,30 @@ func TestOperationsAPI(t *testing.T) { c := newRequestContextWithParams(w, req, map[string]string{"id": createdID}) opRouter.GetOperation(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.Operation - assert.NoError(tt, json.NewDecoder(w.Body).Decode(&resp)) - assert.True(tt, resp.Done) - assert.Empty(tt, resp.Result.Error) + assert.NoError(t, json.NewDecoder(w.Body).Decode(&resp)) + assert.True(t, resp.Done) + assert.Empty(t, resp.Result.Error) data, err := json.Marshal(sub) - assert.NoError(tt, err) + assert.NoError(t, err) var responseAsMap map[string]any - assert.NoError(tt, json.Unmarshal(data, &responseAsMap)) - assert.Equal(tt, responseAsMap, resp.Result.Response) + assert.NoError(t, json.Unmarshal(data, &responseAsMap)) + assert.Equal(t, responseAsMap, resp.Result.Response) }) - t.Run("GetOperation", func(tt *testing.T) { - tt.Run("Returns operation after submission", func(ttt *testing.T) { - s := test.ServiceStorage(ttt) - pRouter, didService := setupPresentationRouter(ttt, s) - authorDID := createDID(ttt, didService) - opRouter := setupOperationsRouter(ttt, s) + t.Run("GetOperation", func(t *testing.T) { + t.Run("Returns operation after submission", func(t *testing.T) { + s := test.ServiceStorage(t) + pRouter, didService := setupPresentationRouter(t, s) + authorDID := createDID(t, didService) + opRouter := setupOperationsRouter(t, s) - holderSigner, holderDID := getSigner(ttt) - definition := createPresentationDefinition(ttt, pRouter) - submissionOp := createSubmission(ttt, pRouter, definition.PresentationDefinition.ID, authorDID.DID.ID, VerifiableCredential(), holderDID, holderSigner) + holderSigner, holderDID := getSigner(t) + definition := createPresentationDefinition(t, pRouter) + submissionOp := createSubmission(t, pRouter, definition.PresentationDefinition.ID, authorDID.DID.ID, VerifiableCredential(), holderDID, holderSigner) createdID := submissionOp.ID req := httptest.NewRequest( @@ -75,31 +75,31 @@ func TestOperationsAPI(t *testing.T) { c := newRequestContextWithParams(w, req, map[string]string{"id": createdID}) opRouter.GetOperation(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.Operation - assert.NoError(ttt, json.NewDecoder(w.Body).Decode(&resp)) - assert.False(ttt, resp.Done) - assert.Contains(ttt, resp.ID, "presentations/submissions/") + assert.NoError(t, json.NewDecoder(w.Body).Decode(&resp)) + assert.False(t, resp.Done) + assert.Contains(t, resp.ID, "presentations/submissions/") }) - tt.Run("Returns error when id doesn't exist", func(ttt *testing.T) { - s := test.ServiceStorage(ttt) - opRouter := setupOperationsRouter(ttt, s) + t.Run("Returns error when id doesn't exist", func(t *testing.T) { + s := test.ServiceStorage(t) + opRouter := setupOperationsRouter(t, s) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/operations/some_fake_id", nil) w := httptest.NewRecorder() c := newRequestContextWithParams(w, req, map[string]string{"id": "some_fake_id"}) opRouter.GetOperation(c) - assert.Contains(ttt, w.Body.String(), "operation not found with id") + assert.Contains(t, w.Body.String(), "operation not found with id") }) }) - t.Run("ListOperations", func(tt *testing.T) { - tt.Run("Returns empty when no operations stored", func(ttt *testing.T) { - s := test.ServiceStorage(ttt) - opRouter := setupOperationsRouter(ttt, s) + t.Run("ListOperations", func(t *testing.T) { + t.Run("Returns empty when no operations stored", func(t *testing.T) { + s := test.ServiceStorage(t) + opRouter := setupOperationsRouter(t, s) query := url.QueryEscape("presentations/submissions") req := httptest.NewRequest(http.MethodGet, fmt.Sprintf("https://ssi-service.com/v1/operations?parent=%s", query), nil) @@ -107,25 +107,25 @@ func TestOperationsAPI(t *testing.T) { c := newRequestContextWithParams(w, req, map[string]string{"parent": query}) opRouter.ListOperations(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.ListOperationsResponse - assert.NoError(ttt, json.NewDecoder(w.Body).Decode(&resp)) - assert.Empty(ttt, resp.Operations) + assert.NoError(t, json.NewDecoder(w.Body).Decode(&resp)) + assert.Empty(t, resp.Operations) }) - tt.Run("Returns one operation for every submission", func(ttt *testing.T) { - s := test.ServiceStorage(ttt) - pRouter, didService := setupPresentationRouter(ttt, s) - authorDID := createDID(ttt, didService) - opRouter := setupOperationsRouter(ttt, s) + t.Run("Returns one operation for every submission", func(t *testing.T) { + s := test.ServiceStorage(t) + pRouter, didService := setupPresentationRouter(t, s) + authorDID := createDID(t, didService) + opRouter := setupOperationsRouter(t, s) - def := createPresentationDefinition(ttt, pRouter) - holderSigner, holderDID := getSigner(ttt) - submissionOp := createSubmission(ttt, pRouter, def.PresentationDefinition.ID, authorDID.DID.ID, VerifiableCredential(), holderDID, holderSigner) + def := createPresentationDefinition(t, pRouter) + holderSigner, holderDID := getSigner(t) + submissionOp := createSubmission(t, pRouter, def.PresentationDefinition.ID, authorDID.DID.ID, VerifiableCredential(), holderDID, holderSigner) - holderSigner2, holderDID2 := getSigner(ttt) - submissionOp2 := createSubmission(ttt, pRouter, def.PresentationDefinition.ID, authorDID.DID.ID, VerifiableCredential(), holderDID2, holderSigner2) + holderSigner2, holderDID2 := getSigner(t) + submissionOp2 := createSubmission(t, pRouter, def.PresentationDefinition.ID, authorDID.DID.ID, VerifiableCredential(), holderDID2, holderSigner2) query := url.QueryEscape("presentations/submissions") req := httptest.NewRequest(http.MethodGet, fmt.Sprintf("https://ssi-service.com/v1/operations?parent=%s", query), nil) @@ -133,10 +133,10 @@ func TestOperationsAPI(t *testing.T) { c := newRequestContextWithParams(w, req, map[string]string{"parent": query}) opRouter.ListOperations(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.ListOperationsResponse - assert.NoError(ttt, json.NewDecoder(w.Body).Decode(&resp)) + assert.NoError(t, json.NewDecoder(w.Body).Decode(&resp)) ops := []router.Operation{submissionOp, submissionOp2} diff := cmp.Diff(ops, resp.Operations, cmpopts.IgnoreFields(exchange.PresentationSubmission{}, "DescriptorMap"), @@ -145,19 +145,19 @@ func TestOperationsAPI(t *testing.T) { }), ) if diff != "" { - ttt.Errorf("Mismatch on submissions (-want +got):\n%s", diff) + t.Errorf("Mismatch on submissions (-want +got):\n%s", diff) } }) - tt.Run("Returns operation when filtering to include", func(ttt *testing.T) { - s := test.ServiceStorage(ttt) - pRouter, didService := setupPresentationRouter(ttt, s) - authorDID := createDID(ttt, didService) - opRouter := setupOperationsRouter(ttt, s) + t.Run("Returns operation when filtering to include", func(t *testing.T) { + s := test.ServiceStorage(t) + pRouter, didService := setupPresentationRouter(t, s) + authorDID := createDID(t, didService) + opRouter := setupOperationsRouter(t, s) - def := createPresentationDefinition(ttt, pRouter) - holderSigner, holderDID := getSigner(ttt) - _ = createSubmission(ttt, pRouter, def.PresentationDefinition.ID, authorDID.DID.ID, VerifiableCredential(), holderDID, holderSigner) + def := createPresentationDefinition(t, pRouter) + holderSigner, holderDID := getSigner(t) + _ = createSubmission(t, pRouter, def.PresentationDefinition.ID, authorDID.DID.ID, VerifiableCredential(), holderDID, holderSigner) queryParent := url.QueryEscape("presentations/submissions") queryDone := url.QueryEscape("done=false") @@ -166,26 +166,26 @@ func TestOperationsAPI(t *testing.T) { c := newRequestContextWithParams(w, req, map[string]string{"parent": queryParent, "done": queryDone}) opRouter.ListOperations(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.ListOperationsResponse - assert.NoError(ttt, json.NewDecoder(w.Body).Decode(&resp)) - assert.Len(ttt, resp.Operations, 1) - assert.False(ttt, resp.Operations[0].Done) + assert.NoError(t, json.NewDecoder(w.Body).Decode(&resp)) + assert.Len(t, resp.Operations, 1) + assert.False(t, resp.Operations[0].Done) }) // TODO: Fix pagesize issue on redis - https://github.com/TBD54566975/ssi-service/issues/538 if !strings.Contains(test.Name, "Redis") { - tt.Run("Returns zero operations when filtering to exclude", func(ttt *testing.T) { + t.Run("Returns zero operations when filtering to exclude", func(t *testing.T) { - s := test.ServiceStorage(ttt) - pRouter, didService := setupPresentationRouter(ttt, s) - authorDID := createDID(ttt, didService) - opRouter := setupOperationsRouter(ttt, s) + s := test.ServiceStorage(t) + pRouter, didService := setupPresentationRouter(t, s) + authorDID := createDID(t, didService) + opRouter := setupOperationsRouter(t, s) - def := createPresentationDefinition(ttt, pRouter) - holderSigner, holderDID := getSigner(ttt) - _ = createSubmission(ttt, pRouter, def.PresentationDefinition.ID, authorDID.DID.ID, VerifiableCredential(), holderDID, holderSigner) + def := createPresentationDefinition(t, pRouter) + holderSigner, holderDID := getSigner(t) + _ = createSubmission(t, pRouter, def.PresentationDefinition.ID, authorDID.DID.ID, VerifiableCredential(), holderDID, holderSigner) queryParent := url.QueryEscape("presentations/submissions") queryDone := url.QueryEscape("done=true") @@ -195,26 +195,26 @@ func TestOperationsAPI(t *testing.T) { c := newRequestContextWithParams(w, req, map[string]string{"parent": queryParent, "filter": queryDone}) opRouter.ListOperations(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.ListOperationsResponse - assert.NoError(ttt, json.NewDecoder(w.Body).Decode(&resp)) - assert.Empty(ttt, resp.Operations) + assert.NoError(t, json.NewDecoder(w.Body).Decode(&resp)) + assert.Empty(t, resp.Operations) }) } // TODO: Fix pagesize issue on redis - https://github.com/TBD54566975/ssi-service/issues/538 if !strings.Contains(test.Name, "Redis") { - tt.Run("Returns zero operations when wrong parent is specified", func(ttt *testing.T) { + t.Run("Returns zero operations when wrong parent is specified", func(t *testing.T) { - s := test.ServiceStorage(ttt) - pRouter, didService := setupPresentationRouter(ttt, s) - authorDID := createDID(ttt, didService) - opRouter := setupOperationsRouter(ttt, s) + s := test.ServiceStorage(t) + pRouter, didService := setupPresentationRouter(t, s) + authorDID := createDID(t, didService) + opRouter := setupOperationsRouter(t, s) - def := createPresentationDefinition(ttt, pRouter) - holderSigner, holderDID := getSigner(ttt) - _ = createSubmission(ttt, pRouter, def.PresentationDefinition.ID, authorDID.DID.ID, VerifiableCredential(), holderDID, holderSigner) + def := createPresentationDefinition(t, pRouter) + holderSigner, holderDID := getSigner(t) + _ = createSubmission(t, pRouter, def.PresentationDefinition.ID, authorDID.DID.ID, VerifiableCredential(), holderDID, holderSigner) queryParent := url.QueryEscape("/presentations/other") req := httptest.NewRequest(http.MethodGet, fmt.Sprintf("https://ssi-service.com/v1/operations?parent=%s", queryParent), nil) @@ -222,26 +222,26 @@ func TestOperationsAPI(t *testing.T) { c := newRequestContextWithParams(w, req, map[string]string{"parent": queryParent}) opRouter.ListOperations(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.ListOperationsResponse - assert.NoError(ttt, json.NewDecoder(w.Body).Decode(&resp)) - assert.Empty(ttt, resp.Operations) + assert.NoError(t, json.NewDecoder(w.Body).Decode(&resp)) + assert.Empty(t, resp.Operations) }) } }) - t.Run("CancelOperation", func(tt *testing.T) { - tt.Run("Marks an operation as done", func(ttt *testing.T) { - s := test.ServiceStorage(ttt) - pRouter, didService := setupPresentationRouter(ttt, s) - authorDID := createDID(ttt, didService) - opRouter := setupOperationsRouter(ttt, s) + t.Run("CancelOperation", func(t *testing.T) { + t.Run("Marks an operation as done", func(t *testing.T) { + s := test.ServiceStorage(t) + pRouter, didService := setupPresentationRouter(t, s) + authorDID := createDID(t, didService) + opRouter := setupOperationsRouter(t, s) - holderSigner, holderDID := getSigner(ttt) - definition := createPresentationDefinition(ttt, pRouter) - submissionOp := createSubmission(ttt, pRouter, definition.PresentationDefinition.ID, authorDID.DID.ID, VerifiableCredential(), holderDID, holderSigner) + holderSigner, holderDID := getSigner(t) + definition := createPresentationDefinition(t, pRouter) + submissionOp := createSubmission(t, pRouter, definition.PresentationDefinition.ID, authorDID.DID.ID, VerifiableCredential(), holderDID, holderSigner) createdID := submissionOp.ID req := httptest.NewRequest(http.MethodPut, fmt.Sprintf("https://ssi-service.com/v1/operations/%s", createdID), nil) @@ -249,32 +249,32 @@ func TestOperationsAPI(t *testing.T) { c := newRequestContextWithParams(w, req, map[string]string{"id": createdID}) opRouter.CancelOperation(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.Operation - assert.NoError(ttt, json.NewDecoder(w.Body).Decode(&resp)) - assert.True(ttt, resp.Done) - assert.Contains(ttt, resp.Result.Response, "verifiablePresentation") - assert.Equal(ttt, "cancelled", resp.Result.Response.(map[string]any)["status"]) + assert.NoError(t, json.NewDecoder(w.Body).Decode(&resp)) + assert.True(t, resp.Done) + assert.Contains(t, resp.Result.Response, "verifiablePresentation") + assert.Equal(t, "cancelled", resp.Result.Response.(map[string]any)["status"]) }) - tt.Run("Returns error when operation is done already", func(ttt *testing.T) { - s := test.ServiceStorage(ttt) - pRouter, didService := setupPresentationRouter(ttt, s) - authorDID := createDID(ttt, didService) - opRouter := setupOperationsRouter(ttt, s) + t.Run("Returns error when operation is done already", func(t *testing.T) { + s := test.ServiceStorage(t) + pRouter, didService := setupPresentationRouter(t, s) + authorDID := createDID(t, didService) + opRouter := setupOperationsRouter(t, s) - holderSigner, holderDID := getSigner(ttt) - definition := createPresentationDefinition(ttt, pRouter) - submissionOp := createSubmission(ttt, pRouter, definition.PresentationDefinition.ID, authorDID.DID.ID, VerifiableCredential(), holderDID, holderSigner) - _ = reviewSubmission(ttt, pRouter, opstorage.StatusObjectID(submissionOp.ID)) + holderSigner, holderDID := getSigner(t) + definition := createPresentationDefinition(t, pRouter) + submissionOp := createSubmission(t, pRouter, definition.PresentationDefinition.ID, authorDID.DID.ID, VerifiableCredential(), holderDID, holderSigner) + _ = reviewSubmission(t, pRouter, opstorage.StatusObjectID(submissionOp.ID)) createdID := submissionOp.ID req := httptest.NewRequest(http.MethodPut, fmt.Sprintf("https://ssi-service.com/v1/operations/%s", createdID), nil) w := httptest.NewRecorder() c := newRequestContextWithParams(w, req, map[string]string{"id": createdID}) opRouter.CancelOperation(c) - assert.Contains(ttt, w.Body.String(), "operation already marked as done") + assert.Contains(t, w.Body.String(), "operation already marked as done") }) }) }) diff --git a/pkg/server/server_presentation_test.go b/pkg/server/server_presentation_test.go index afc08143e..a661f424d 100644 --- a/pkg/server/server_presentation_test.go +++ b/pkg/server/server_presentation_test.go @@ -56,23 +56,23 @@ func TestPresentationAPI(t *testing.T) { assert.NoError(t, err) for _, test := range testutil.TestDatabases { - t.Run(test.Name, func(tt *testing.T) { - tt.Run("Verify a Verifiable Presentation", func(ttt *testing.T) { - db := test.ServiceStorage(ttt) - presRouter, _ := setupPresentationRouter(ttt, db) + t.Run(test.Name, func(t *testing.T) { + t.Run("Verify a Verifiable Presentation", func(t *testing.T) { + db := test.ServiceStorage(t) + presRouter, _ := setupPresentationRouter(t, db) // first, create a credential using the service - keyStoreService, _ := testKeyStoreService(ttt, db) - didService, _ := testDIDService(ttt, db, keyStoreService, nil) - schemaService := testSchemaService(ttt, db, keyStoreService, didService) - credRouter := testCredentialRouter(ttt, db, keyStoreService, didService, schemaService) + keyStoreService, _ := testKeyStoreService(t, db) + didService, _ := testDIDService(t, db, keyStoreService, nil) + schemaService := testSchemaService(t, db, keyStoreService, didService) + credRouter := testCredentialRouter(t, db, keyStoreService, didService, schemaService) issuerDID, err := didService.CreateDIDByMethod(context.Background(), did.CreateDIDRequest{ Method: didsdk.KeyMethod, KeyType: crypto.Ed25519, }) - assert.NoError(ttt, err) - assert.NotEmpty(ttt, issuerDID) + assert.NoError(t, err) + assert.NotEmpty(t, issuerDID) // good request createCredRequest := router.CreateCredentialRequest{ @@ -85,22 +85,22 @@ func TestPresentationAPI(t *testing.T) { }, Expiry: time.Now().Add(24 * time.Hour).Format(time.RFC3339), } - requestValue := newRequestValue(ttt, createCredRequest) + requestValue := newRequestValue(t, createCredRequest) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/credentials", requestValue) w := httptest.NewRecorder() c := newRequestContext(w, req) credRouter.CreateCredential(c) - assert.True(ttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var createResp router.CreateCredentialResponse err = json.NewDecoder(w.Body).Decode(&createResp) - assert.NoError(ttt, err) + assert.NoError(t, err) - assert.NotEmpty(ttt, createResp.CredentialJWT) - assert.NoError(ttt, err) - assert.Equal(ttt, createResp.Credential.Issuer, issuerDID.DID.ID) + assert.NotEmpty(t, createResp.CredentialJWT) + assert.NoError(t, err) + assert.Equal(t, createResp.Credential.Issuer, issuerDID.DID.ID) - holderSigner, holderDID := getSigner(ttt) + holderSigner, holderDID := getSigner(t) testPresentation := credential.VerifiablePresentation{ Context: []string{"https://www.w3.org/2018/credentials/v1", "https://w3id.org/security/suites/jws-2020/v1"}, @@ -108,94 +108,94 @@ func TestPresentationAPI(t *testing.T) { Holder: holderDID.String(), } - ttt.Run("Invalid Verifiable Presentation with no credentials", func(tttt *testing.T) { + t.Run("Invalid Verifiable Presentation with no credentials", func(t *testing.T) { // use the sdk to create a vp emptyPresentation, err := integrity.SignVerifiablePresentationJWT(holderSigner, &integrity.JWTVVPParameters{Audience: []string{holderSigner.ID}}, testPresentation) - assert.NoError(tttt, err) + assert.NoError(t, err) badPresentation := string(emptyPresentation[:10]) - value := newRequestValue(tttt, router.VerifyPresentationRequest{PresentationJWT: keyaccess.JWTPtr(badPresentation)}) + value := newRequestValue(t, router.VerifyPresentationRequest{PresentationJWT: keyaccess.JWTPtr(badPresentation)}) req := httptest.NewRequest(http.MethodPut, fmt.Sprintf("https://ssi-service.com/v1/presentations/verification"), value) w := httptest.NewRecorder() c := newRequestContext(w, req) presRouter.VerifyPresentation(c) - assert.True(tttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.VerifyPresentationResponse - assert.NoError(tttt, json.NewDecoder(w.Body).Decode(&resp)) - assert.False(tttt, resp.Verified) - assert.Equal(tttt, "verifying JWT presentation: parsing JWT: parsing vp token: invalid JWT", resp.Reason) + assert.NoError(t, json.NewDecoder(w.Body).Decode(&resp)) + assert.False(t, resp.Verified) + assert.Equal(t, "verifying JWT presentation: parsing JWT: parsing vp token: invalid JWT", resp.Reason) }) - ttt.Run("Valid Verifiable Presentation with no credentials", func(tttt *testing.T) { + t.Run("Valid Verifiable Presentation with no credentials", func(t *testing.T) { // use the sdk to create a vp emptyPresentation, err := integrity.SignVerifiablePresentationJWT(holderSigner, &integrity.JWTVVPParameters{Audience: []string{holderSigner.ID}}, testPresentation) - assert.NoError(tttt, err) + assert.NoError(t, err) value := newRequestValue(t, router.VerifyPresentationRequest{PresentationJWT: keyaccess.JWTPtr(string(emptyPresentation))}) req := httptest.NewRequest(http.MethodPut, fmt.Sprintf("https://ssi-service.com/v1/presentations/verification"), value) w := httptest.NewRecorder() c := newRequestContext(w, req) presRouter.VerifyPresentation(c) - assert.True(tttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.VerifyPresentationResponse - assert.NoError(tttt, json.NewDecoder(w.Body).Decode(&resp)) - assert.True(tttt, resp.Verified) + assert.NoError(t, json.NewDecoder(w.Body).Decode(&resp)) + assert.True(t, resp.Verified) }) - ttt.Run("Invalid Verifiable Presentation with invalid credential signature", func(tttt *testing.T) { + t.Run("Invalid Verifiable Presentation with invalid credential signature", func(t *testing.T) { // add credential to the vp badCredJWT := createResp.CredentialJWT.String()[:10] testPresentation.VerifiableCredential = []any{badCredJWT} // use the sdk to create a vp emptyPresentation, err := integrity.SignVerifiablePresentationJWT(holderSigner, &integrity.JWTVVPParameters{Audience: []string{holderSigner.ID}}, testPresentation) - assert.NoError(tt, err) + assert.NoError(t, err) - value := newRequestValue(tttt, router.VerifyPresentationRequest{PresentationJWT: keyaccess.JWTPtr(string(emptyPresentation))}) + value := newRequestValue(t, router.VerifyPresentationRequest{PresentationJWT: keyaccess.JWTPtr(string(emptyPresentation))}) req := httptest.NewRequest(http.MethodPut, fmt.Sprintf("https://ssi-service.com/v1/presentations/verification"), value) w := httptest.NewRecorder() c := newRequestContext(w, req) presRouter.VerifyPresentation(c) - assert.True(tttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.VerifyPresentationResponse - assert.NoError(tttt, json.NewDecoder(w.Body).Decode(&resp)) - assert.False(tttt, resp.Verified) - assert.Contains(tttt, resp.Reason, "verifying credential 0: parsing JWT: parsing credential token: invalid JWT") + assert.NoError(t, json.NewDecoder(w.Body).Decode(&resp)) + assert.False(t, resp.Verified) + assert.Contains(t, resp.Reason, "verifying credential 0: parsing JWT: parsing credential token: invalid JWT") }) - ttt.Run("Valid Verifiable Presentation with valid credential signature", func(tttt *testing.T) { + t.Run("Valid Verifiable Presentation with valid credential signature", func(t *testing.T) { // add credential to the vp testPresentation.VerifiableCredential = []any{createResp.CredentialJWT} // use the sdk to create a vp emptyPresentation, err := integrity.SignVerifiablePresentationJWT(holderSigner, &integrity.JWTVVPParameters{Audience: []string{holderSigner.ID}}, testPresentation) - assert.NoError(tttt, err) + assert.NoError(t, err) - value := newRequestValue(tttt, router.VerifyPresentationRequest{PresentationJWT: keyaccess.JWTPtr(string(emptyPresentation))}) + value := newRequestValue(t, router.VerifyPresentationRequest{PresentationJWT: keyaccess.JWTPtr(string(emptyPresentation))}) req := httptest.NewRequest(http.MethodPut, fmt.Sprintf("https://ssi-service.com/v1/presentations/verification"), value) w := httptest.NewRecorder() c := newRequestContext(w, req) presRouter.VerifyPresentation(c) - assert.True(tttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.VerifyPresentationResponse - assert.NoError(tttt, json.NewDecoder(w.Body).Decode(&resp)) - assert.True(tttt, resp.Verified) + assert.NoError(t, json.NewDecoder(w.Body).Decode(&resp)) + assert.True(t, resp.Verified) }) }) - tt.Run("Create, Get, and Delete Presentation Definition", func(ttt *testing.T) { - s := test.ServiceStorage(ttt) - pRouter, _ := setupPresentationRouter(ttt, s) + t.Run("Create, Get, and Delete Presentation Definition", func(t *testing.T) { + s := test.ServiceStorage(t) + pRouter, _ := setupPresentationRouter(t, s) var createdID string { - resp := createPresentationDefinition(ttt, pRouter, WithInputDescriptors(inputDescriptors)) + resp := createPresentationDefinition(t, pRouter, WithInputDescriptors(inputDescriptors)) if diff := cmp.Diff(*pd, resp.PresentationDefinition, cmpopts.IgnoreFields(exchange.PresentationDefinition{}, "ID")); diff != "" { - ttt.Errorf("PresentationDefinition mismatch (-want +got):\n%s", diff) + t.Errorf("PresentationDefinition mismatch (-want +got):\n%s", diff) } createdID = resp.PresentationDefinition.ID @@ -206,13 +206,13 @@ func TestPresentationAPI(t *testing.T) { w := httptest.NewRecorder() c := newRequestContextWithParams(w, req, map[string]string{"id": createdID}) pRouter.GetDefinition(c) - assert.True(ttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.GetPresentationDefinitionResponse - assert.NoError(ttt, json.NewDecoder(w.Body).Decode(&resp)) - assert.Equal(ttt, createdID, resp.PresentationDefinition.ID) + assert.NoError(t, json.NewDecoder(w.Body).Decode(&resp)) + assert.Equal(t, createdID, resp.PresentationDefinition.ID) if diff := cmp.Diff(*pd, resp.PresentationDefinition, cmpopts.IgnoreFields(exchange.PresentationDefinition{}, "ID")); diff != "" { - ttt.Errorf("PresentationDefinition mismatch (-want +got):\n%s", diff) + t.Errorf("PresentationDefinition mismatch (-want +got):\n%s", diff) } } { @@ -222,14 +222,14 @@ func TestPresentationAPI(t *testing.T) { c := newRequestContext(w, req) pRouter.ListDefinitions(c) - assert.True(ttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.ListDefinitionsResponse - assert.NoError(ttt, json.NewDecoder(w.Body).Decode(&resp)) - assert.Len(ttt, resp.Definitions, 1) - assert.Equal(ttt, createdID, resp.Definitions[0].ID) + assert.NoError(t, json.NewDecoder(w.Body).Decode(&resp)) + assert.Len(t, resp.Definitions, 1) + assert.Equal(t, createdID, resp.Definitions[0].ID) if diff := cmp.Diff(pd, resp.Definitions[0], cmpopts.IgnoreFields(exchange.PresentationDefinition{}, "ID")); diff != "" { - ttt.Errorf("PresentationDefinition mismatch (-want +got):\n%s", diff) + t.Errorf("PresentationDefinition mismatch (-want +got):\n%s", diff) } } { @@ -238,7 +238,7 @@ func TestPresentationAPI(t *testing.T) { w := httptest.NewRecorder() c := newRequestContextWithParams(w, req, map[string]string{"id": createdID}) pRouter.DeleteDefinition(c) - assert.True(ttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) } { // And we cannot get the PD after it's been deleted. @@ -246,31 +246,31 @@ func TestPresentationAPI(t *testing.T) { w := httptest.NewRecorder() c := newRequestContextWithParams(w, req, map[string]string{"id": createdID}) pRouter.GetDefinition(c) - assert.Contains(ttt, w.Body.String(), "not found") + assert.Contains(t, w.Body.String(), "not found") } }) - tt.Run("List presentation requests returns empty", func(tt *testing.T) { - s := test.ServiceStorage(tt) - pRouter, _ := setupPresentationRouter(tt, s) + t.Run("List presentation requests returns empty", func(t *testing.T) { + s := test.ServiceStorage(t) + pRouter, _ := setupPresentationRouter(t, s) req := httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/presentations/requests", nil) w := httptest.NewRecorder() c := newRequestContext(w, req) pRouter.ListRequests(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.ListPresentationRequestsResponse - assert.NoError(tt, json.NewDecoder(w.Body).Decode(&resp)) - assert.Empty(tt, resp.Requests) + assert.NoError(t, json.NewDecoder(w.Body).Decode(&resp)) + assert.Empty(t, resp.Requests) }) - tt.Run("Get presentation requests returns created request", func(ttt *testing.T) { - s := test.ServiceStorage(ttt) - pRouter, didService := setupPresentationRouter(ttt, s) - issuerDID := createDID(ttt, didService) - def := createPresentationDefinition(ttt, pRouter) - req1 := createPresentationRequest(ttt, pRouter, def.PresentationDefinition.ID, issuerDID.DID) + t.Run("Get presentation requests returns created request", func(t *testing.T) { + s := test.ServiceStorage(t) + pRouter, didService := setupPresentationRouter(t, s) + issuerDID := createDID(t, didService) + def := createPresentationDefinition(t, pRouter) + req1 := createPresentationRequest(t, pRouter, def.PresentationDefinition.ID, issuerDID.DID) req := httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/presentations/requests/"+req1.Request.ID, nil) w := httptest.NewRecorder() @@ -279,129 +279,129 @@ func TestPresentationAPI(t *testing.T) { } c := newRequestContextWithParams(w, req, params) pRouter.GetRequest(c) - assert.True(ttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.GetRequestResponse - assert.NoError(ttt, json.NewDecoder(w.Body).Decode(&resp)) - assert.Equal(ttt, req1.Request, resp.Request) - assert.Equal(ttt, "my_callback_url", resp.Request.CallbackURL) + assert.NoError(t, json.NewDecoder(w.Body).Decode(&resp)) + assert.Equal(t, req1.Request, resp.Request) + assert.Equal(t, "my_callback_url", resp.Request.CallbackURL) }) - tt.Run("List presentation requests returns many requests", func(ttt *testing.T) { - s := test.ServiceStorage(ttt) - pRouter, didService := setupPresentationRouter(ttt, s) - issuerDID := createDID(ttt, didService) - def := createPresentationDefinition(ttt, pRouter) - req1 := createPresentationRequest(ttt, pRouter, def.PresentationDefinition.ID, issuerDID.DID) - req2 := createPresentationRequest(ttt, pRouter, def.PresentationDefinition.ID, issuerDID.DID) + t.Run("List presentation requests returns many requests", func(t *testing.T) { + s := test.ServiceStorage(t) + pRouter, didService := setupPresentationRouter(t, s) + issuerDID := createDID(t, didService) + def := createPresentationDefinition(t, pRouter) + req1 := createPresentationRequest(t, pRouter, def.PresentationDefinition.ID, issuerDID.DID) + req2 := createPresentationRequest(t, pRouter, def.PresentationDefinition.ID, issuerDID.DID) req := httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/presentations/requests", nil) w := httptest.NewRecorder() c := newRequestContext(w, req) pRouter.ListRequests(c) - assert.True(ttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.ListPresentationRequestsResponse - assert.NoError(ttt, json.NewDecoder(w.Body).Decode(&resp)) - assert.Len(ttt, resp.Requests, 2) - assert.ElementsMatch(ttt, resp.Requests, []model.Request{ + assert.NoError(t, json.NewDecoder(w.Body).Decode(&resp)) + assert.Len(t, resp.Requests, 2) + assert.ElementsMatch(t, resp.Requests, []model.Request{ *req1.Request, *req2.Request, }) - assert.Equal(ttt, "my_callback_url", resp.Requests[0].CallbackURL) + assert.Equal(t, "my_callback_url", resp.Requests[0].CallbackURL) }) - tt.Run("List definitions returns empty", func(tt *testing.T) { - s := test.ServiceStorage(tt) - pRouter, _ := setupPresentationRouter(tt, s) + t.Run("List definitions returns empty", func(t *testing.T) { + s := test.ServiceStorage(t) + pRouter, _ := setupPresentationRouter(t, s) req := httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/presentations/definitions", nil) w := httptest.NewRecorder() c := newRequestContext(w, req) pRouter.ListDefinitions(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.ListDefinitionsResponse - assert.NoError(tt, json.NewDecoder(w.Body).Decode(&resp)) - assert.Empty(tt, resp.Definitions) + assert.NoError(t, json.NewDecoder(w.Body).Decode(&resp)) + assert.Empty(t, resp.Definitions) }) - tt.Run("List definitions returns many definitions", func(ttt *testing.T) { - s := test.ServiceStorage(ttt) - pRouter, _ := setupPresentationRouter(ttt, s) - def1 := createPresentationDefinition(ttt, pRouter) - def2 := createPresentationDefinition(ttt, pRouter) + t.Run("List definitions returns many definitions", func(t *testing.T) { + s := test.ServiceStorage(t) + pRouter, _ := setupPresentationRouter(t, s) + def1 := createPresentationDefinition(t, pRouter) + def2 := createPresentationDefinition(t, pRouter) req := httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/presentations/definitions", nil) w := httptest.NewRecorder() c := newRequestContext(w, req) pRouter.ListDefinitions(c) - assert.True(ttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.ListDefinitionsResponse - assert.NoError(ttt, json.NewDecoder(w.Body).Decode(&resp)) - assert.Len(ttt, resp.Definitions, 2) - assert.ElementsMatch(ttt, resp.Definitions, []*exchange.PresentationDefinition{ + assert.NoError(t, json.NewDecoder(w.Body).Decode(&resp)) + assert.Len(t, resp.Definitions, 2) + assert.ElementsMatch(t, resp.Definitions, []*exchange.PresentationDefinition{ &def1.PresentationDefinition, &def2.PresentationDefinition, }) }) - tt.Run("Create returns error without input descriptors", func(ttt *testing.T) { - s := test.ServiceStorage(ttt) - pRouter, _ := setupPresentationRouter(ttt, s) + t.Run("Create returns error without input descriptors", func(t *testing.T) { + s := test.ServiceStorage(t) + pRouter, _ := setupPresentationRouter(t, s) request := router.CreatePresentationDefinitionRequest{} - value := newRequestValue(ttt, request) + value := newRequestValue(t, request) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/presentations/definitions", value) w := httptest.NewRecorder() c := newRequestContext(w, req) pRouter.CreateDefinition(c) - assert.Contains(ttt, w.Body.String(), "inputDescriptors is a required field") + assert.Contains(t, w.Body.String(), "inputDescriptors is a required field") }) - tt.Run("Get without an ID returns error", func(ttt *testing.T) { - s := test.ServiceStorage(ttt) - pRouter, _ := setupPresentationRouter(ttt, s) + t.Run("Get without an ID returns error", func(t *testing.T) { + s := test.ServiceStorage(t) + pRouter, _ := setupPresentationRouter(t, s) req := httptest.NewRequest(http.MethodGet, fmt.Sprintf("https://ssi-service.com/v1/presentations/definitions/%s", pd.ID), nil) w := httptest.NewRecorder() c := newRequestContextWithParams(w, req, map[string]string{"id": pd.ID}) pRouter.GetDefinition(c) - assert.Contains(ttt, w.Body.String(), "not found") + assert.Contains(t, w.Body.String(), "not found") }) - tt.Run("Delete without an ID returns error", func(ttt *testing.T) { - s := test.ServiceStorage(ttt) - pRouter, _ := setupPresentationRouter(ttt, s) + t.Run("Delete without an ID returns error", func(t *testing.T) { + s := test.ServiceStorage(t) + pRouter, _ := setupPresentationRouter(t, s) req := httptest.NewRequest(http.MethodDelete, fmt.Sprintf("https://ssi-service.com/v1/presentations/definitions/%s", pd.ID), nil) w := httptest.NewRecorder() c := newRequestContextWithParams(w, req, map[string]string{"id": pd.ID}) pRouter.DeleteDefinition(c) - assert.Contains(ttt, w.Body.String(), fmt.Sprintf("deleting presentation definition with id: %s", pd.ID)) + assert.Contains(t, w.Body.String(), fmt.Sprintf("deleting presentation definition with id: %s", pd.ID)) }) - tt.Run("Submission endpoints", func(ttt *testing.T) { - ttt.Run("Get non-existing ID returns error", func(tttt *testing.T) { - s := test.ServiceStorage(tttt) - pRouter, _ := setupPresentationRouter(tttt, s) + t.Run("Submission endpoints", func(t *testing.T) { + t.Run("Get non-existing ID returns error", func(t *testing.T) { + s := test.ServiceStorage(t) + pRouter, _ := setupPresentationRouter(t, s) req := httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/presentations/submissions/myrandomid", nil) w := httptest.NewRecorder() c := newRequestContextWithParams(w, req, map[string]string{"id": "myrandomid"}) pRouter.GetSubmission(c) - assert.Contains(tttt, w.Body.String(), "not found") + assert.Contains(t, w.Body.String(), "not found") }) - ttt.Run("Get returns submission after creation", func(tttt *testing.T) { - s := test.ServiceStorage(tttt) - pRouter, didService := setupPresentationRouter(tttt, s) - authorDID := createDID(tttt, didService) + t.Run("Get returns submission after creation", func(t *testing.T) { + s := test.ServiceStorage(t) + pRouter, didService := setupPresentationRouter(t, s) + authorDID := createDID(t, didService) - holderSigner, holderDID := getSigner(tttt) - definition := createPresentationDefinition(tttt, pRouter) - op := createSubmission(tttt, pRouter, definition.PresentationDefinition.ID, authorDID.DID.ID, VerifiableCredential( + holderSigner, holderDID := getSigner(t) + definition := createPresentationDefinition(t, pRouter) + op := createSubmission(t, pRouter, definition.PresentationDefinition.ID, authorDID.DID.ID, VerifiableCredential( WithCredentialSubject(credential.CredentialSubject{ "additionalName": "McLovin", "dateOfBirth": "1987-01-02", @@ -415,23 +415,23 @@ func TestPresentationAPI(t *testing.T) { c := newRequestContextWithParams(w, req, map[string]string{"id": opstorage.StatusObjectID(op.ID)}) pRouter.GetSubmission(c) - assert.True(tttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.GetSubmissionResponse - assert.NoError(tttt, json.NewDecoder(w.Body).Decode(&resp)) - assert.Equal(tttt, opstorage.StatusObjectID(op.ID), resp.GetSubmission().ID) - assert.Equal(tttt, definition.PresentationDefinition.ID, resp.GetSubmission().DefinitionID) - assert.Equal(tttt, "pending", resp.Submission.Status) + assert.NoError(t, json.NewDecoder(w.Body).Decode(&resp)) + assert.Equal(t, opstorage.StatusObjectID(op.ID), resp.GetSubmission().ID) + assert.Equal(t, definition.PresentationDefinition.ID, resp.GetSubmission().DefinitionID) + assert.Equal(t, "pending", resp.Submission.Status) }) - ttt.Run("Create well formed submission returns operation", func(tttt *testing.T) { - s := test.ServiceStorage(tttt) - pRouter, didService := setupPresentationRouter(tttt, s) - authorDID := createDID(tttt, didService) + t.Run("Create well formed submission returns operation", func(t *testing.T) { + s := test.ServiceStorage(t) + pRouter, didService := setupPresentationRouter(t, s) + authorDID := createDID(t, didService) - holderSigner, holderDID := getSigner(tttt) - definition := createPresentationDefinition(tttt, pRouter) - request := createSubmissionRequest(tttt, definition.PresentationDefinition.ID, authorDID.DID.ID, VerifiableCredential( + holderSigner, holderDID := getSigner(t) + definition := createPresentationDefinition(t, pRouter) + request := createSubmissionRequest(t, definition.PresentationDefinition.ID, authorDID.DID.ID, VerifiableCredential( WithCredentialSubject(credential.CredentialSubject{ "additionalName": "McLovin", "dateOfBirth": "1987-01-02", @@ -440,36 +440,36 @@ func TestPresentationAPI(t *testing.T) { "id": "did:web:andresuribe.com", })), holderSigner, holderDID) - value := newRequestValue(tttt, request) + value := newRequestValue(t, request) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/presentations/submissions", value) w := httptest.NewRecorder() c := newRequestContext(w, req) pRouter.CreateSubmission(c) - assert.True(tttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.Operation - assert.NoError(tttt, json.NewDecoder(w.Body).Decode(&resp)) - assert.Contains(tttt, resp.ID, "presentations/submissions/") - assert.False(tttt, resp.Done) - assert.Zero(tttt, resp.Result) + assert.NoError(t, json.NewDecoder(w.Body).Decode(&resp)) + assert.Contains(t, resp.ID, "presentations/submissions/") + assert.False(t, resp.Done) + assert.Zero(t, resp.Result) }) - ttt.Run("Review submission returns approved submission", func(tttt *testing.T) { - s := test.ServiceStorage(tttt) - pRouter, didService := setupPresentationRouter(tttt, s) - authorDID := createDID(tttt, didService) + t.Run("Review submission returns approved submission", func(t *testing.T) { + s := test.ServiceStorage(t) + pRouter, didService := setupPresentationRouter(t, s) + authorDID := createDID(t, didService) - holderSigner, holderDID := getSigner(tttt) - definition := createPresentationDefinition(tttt, pRouter) - submissionOp := createSubmission(tttt, pRouter, definition.PresentationDefinition.ID, authorDID.DID.ID, VerifiableCredential(), holderDID, holderSigner) + holderSigner, holderDID := getSigner(t) + definition := createPresentationDefinition(t, pRouter) + submissionOp := createSubmission(t, pRouter, definition.PresentationDefinition.ID, authorDID.DID.ID, VerifiableCredential(), holderDID, holderSigner) request := router.ReviewSubmissionRequest{ Approved: true, Reason: "because I want to", } - value := newRequestValue(tttt, request) + value := newRequestValue(t, request) createdID := opstorage.StatusObjectID(submissionOp.ID) req := httptest.NewRequest( http.MethodPut, @@ -479,33 +479,33 @@ func TestPresentationAPI(t *testing.T) { c := newRequestContextWithParams(w, req, map[string]string{"id": createdID}) pRouter.ReviewSubmission(c) - assert.True(tttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.ReviewSubmissionResponse - assert.NoError(tttt, json.NewDecoder(w.Body).Decode(&resp)) - assert.Equal(tttt, "because I want to", resp.Reason) - assert.NotEmpty(tttt, resp.GetSubmission().ID) - assert.Equal(tttt, "approved", resp.Status) - assert.Equal(tttt, definition.PresentationDefinition.ID, resp.GetSubmission().DefinitionID) + assert.NoError(t, json.NewDecoder(w.Body).Decode(&resp)) + assert.Equal(t, "because I want to", resp.Reason) + assert.NotEmpty(t, resp.GetSubmission().ID) + assert.Equal(t, "approved", resp.Status) + assert.Equal(t, definition.PresentationDefinition.ID, resp.GetSubmission().DefinitionID) }) - ttt.Run("Review submission twice fails", func(tttt *testing.T) { - s := test.ServiceStorage(tttt) - pRouter, didService := setupPresentationRouter(tttt, s) - authorDID := createDID(tttt, didService) + t.Run("Review submission twice fails", func(t *testing.T) { + s := test.ServiceStorage(t) + pRouter, didService := setupPresentationRouter(t, s) + authorDID := createDID(t, didService) - holderSigner, holderDID := getSigner(tttt) - definition := createPresentationDefinition(tttt, pRouter) - submissionOp := createSubmission(tttt, pRouter, definition.PresentationDefinition.ID, authorDID.DID.ID, VerifiableCredential(), holderDID, holderSigner) + holderSigner, holderDID := getSigner(t) + definition := createPresentationDefinition(t, pRouter) + submissionOp := createSubmission(t, pRouter, definition.PresentationDefinition.ID, authorDID.DID.ID, VerifiableCredential(), holderDID, holderSigner) createdID := opstorage.StatusObjectID(submissionOp.ID) - _ = reviewSubmission(tttt, pRouter, createdID) + _ = reviewSubmission(t, pRouter, createdID) request := router.ReviewSubmissionRequest{ Approved: true, Reason: "because I want to review again", } - value := newRequestValue(tttt, request) + value := newRequestValue(t, request) req := httptest.NewRequest( http.MethodPut, fmt.Sprintf("https://ssi-service.com/v1/presentations/submissions/%s/review", createdID), @@ -513,28 +513,28 @@ func TestPresentationAPI(t *testing.T) { w := httptest.NewRecorder() c := newRequestContextWithParams(w, req, map[string]string{"id": createdID}) pRouter.ReviewSubmission(c) - assert.Contains(tttt, w.Body.String(), "operation already marked as done") + assert.Contains(t, w.Body.String(), "operation already marked as done") }) - ttt.Run("List submissions returns empty when there are none", func(tttt *testing.T) { - s := test.ServiceStorage(tttt) - pRouter, _ := setupPresentationRouter(tttt, s) + t.Run("List submissions returns empty when there are none", func(t *testing.T) { + s := test.ServiceStorage(t) + pRouter, _ := setupPresentationRouter(t, s) req := httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/presentations/submissions", nil) w := httptest.NewRecorder() c := newRequestContext(w, req) pRouter.ListSubmissions(c) - assert.True(tttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.ListSubmissionResponse - assert.NoError(tttt, json.NewDecoder(w.Body).Decode(&resp)) - assert.Empty(tttt, resp.Submissions) + assert.NoError(t, json.NewDecoder(w.Body).Decode(&resp)) + assert.Empty(t, resp.Submissions) }) - ttt.Run("List submissions invalid page size fails", func(tttt *testing.T) { - s := test.ServiceStorage(tttt) - pRouter, _ := setupPresentationRouter(tttt, s) + t.Run("List submissions invalid page size fails", func(t *testing.T) { + s := test.ServiceStorage(t) + pRouter, _ := setupPresentationRouter(t, s) w := httptest.NewRecorder() badParams := url.Values{ @@ -544,12 +544,12 @@ func TestPresentationAPI(t *testing.T) { c := newRequestContext(w, req) pRouter.ListSubmissions(c) - assert.Contains(tttt, w.Body.String(), "'pageSize' must be greater than 0") + assert.Contains(t, w.Body.String(), "'pageSize' must be greater than 0") }) - ttt.Run("List submissions made up token fails", func(tttt *testing.T) { - s := test.ServiceStorage(tttt) - pRouter, _ := setupPresentationRouter(tttt, s) + t.Run("List submissions made up token fails", func(t *testing.T) { + s := test.ServiceStorage(t) + pRouter, _ := setupPresentationRouter(t, s) w := httptest.NewRecorder() badParams := url.Values{ @@ -560,22 +560,22 @@ func TestPresentationAPI(t *testing.T) { c := newRequestContext(w, req) pRouter.ListSubmissions(c) - assert.Contains(tttt, w.Body.String(), "token value cannot be decoded") + assert.Contains(t, w.Body.String(), "token value cannot be decoded") }) - ttt.Run("List submissions pagination", func(tttt *testing.T) { + t.Run("List submissions pagination", func(t *testing.T) { // TODO: Fix pagesize issue on redis - https://github.com/TBD54566975/ssi-service/issues/538 if strings.Contains(test.Name, "Redis") { - tttt.Skip("skipping pagination test for Redis") + t.Skip("skipping pagination test for Redis") } - s := test.ServiceStorage(tttt) - pRouter, didService := setupPresentationRouter(tttt, s) + s := test.ServiceStorage(t) + pRouter, didService := setupPresentationRouter(t, s) - authorDID := createDID(tttt, didService) + authorDID := createDID(t, didService) - holderSigner, holderDID := getSigner(tttt) - definition := createPresentationDefinition(tttt, pRouter) - _ = createSubmission(tttt, pRouter, definition.PresentationDefinition.ID, authorDID.DID.ID, VerifiableCredential( + holderSigner, holderDID := getSigner(t) + definition := createPresentationDefinition(t, pRouter) + _ = createSubmission(t, pRouter, definition.PresentationDefinition.ID, authorDID.DID.ID, VerifiableCredential( WithCredentialSubject(credential.CredentialSubject{ "additionalName": "McLovin", "dateOfBirth": "1987-01-02", @@ -584,8 +584,8 @@ func TestPresentationAPI(t *testing.T) { "id": "did:web:andresuribe.com", })), holderDID, holderSigner) - mrTeeSigner, mrTeeDID := getSigner(tttt) - _ = createSubmission(tttt, pRouter, definition.PresentationDefinition.ID, authorDID.DID.ID, VerifiableCredential( + mrTeeSigner, mrTeeDID := getSigner(t) + _ = createSubmission(t, pRouter, definition.PresentationDefinition.ID, authorDID.DID.ID, VerifiableCredential( WithCredentialSubject(credential.CredentialSubject{ "additionalName": "Mr. T", "dateOfBirth": "1999-01-02", @@ -604,9 +604,9 @@ func TestPresentationAPI(t *testing.T) { var listSubmissionResponse router.ListSubmissionResponse err := json.NewDecoder(w.Body).Decode(&listSubmissionResponse) - assert.NoError(tttt, err) - assert.NotEmpty(tttt, listSubmissionResponse.NextPageToken) - assert.Len(tttt, listSubmissionResponse.Submissions, 1) + assert.NoError(t, err) + assert.NotEmpty(t, listSubmissionResponse.NextPageToken) + assert.Len(t, listSubmissionResponse.Submissions, 1) w = httptest.NewRecorder() params["pageToken"] = []string{listSubmissionResponse.NextPageToken} @@ -617,24 +617,24 @@ func TestPresentationAPI(t *testing.T) { var listSubmissionsResponse2 router.ListSubmissionResponse err = json.NewDecoder(w.Body).Decode(&listSubmissionsResponse2) - assert.NoError(tttt, err) - assert.Empty(tttt, listSubmissionsResponse2.NextPageToken) - assert.Len(tttt, listSubmissionsResponse2.Submissions, 1) + assert.NoError(t, err) + assert.Empty(t, listSubmissionsResponse2.NextPageToken) + assert.Len(t, listSubmissionsResponse2.Submissions, 1) }) - ttt.Run("List submissions pagination change query between calls returns error", func(tttt *testing.T) { + t.Run("List submissions pagination change query between calls returns error", func(t *testing.T) { // TODO: Fix pagesize issue on redis - https://github.com/TBD54566975/ssi-service/issues/538 if strings.Contains(test.Name, "Redis") { - tttt.Skip("skipping pagination test for Redis") + t.Skip("skipping pagination test for Redis") } - s := test.ServiceStorage(tttt) - pRouter, didService := setupPresentationRouter(tttt, s) + s := test.ServiceStorage(t) + pRouter, didService := setupPresentationRouter(t, s) - authorDID := createDID(tttt, didService) + authorDID := createDID(t, didService) - holderSigner, holderDID := getSigner(tttt) - definition := createPresentationDefinition(tttt, pRouter) - _ = createSubmission(tttt, pRouter, definition.PresentationDefinition.ID, authorDID.DID.ID, VerifiableCredential( + holderSigner, holderDID := getSigner(t) + definition := createPresentationDefinition(t, pRouter) + _ = createSubmission(t, pRouter, definition.PresentationDefinition.ID, authorDID.DID.ID, VerifiableCredential( WithCredentialSubject(credential.CredentialSubject{ "additionalName": "McLovin", "dateOfBirth": "1987-01-02", @@ -643,8 +643,8 @@ func TestPresentationAPI(t *testing.T) { "id": "did:web:andresuribe.com", })), holderDID, holderSigner) - mrTeeSigner, mrTeeDID := getSigner(tttt) - _ = createSubmission(tttt, pRouter, definition.PresentationDefinition.ID, authorDID.DID.ID, VerifiableCredential( + mrTeeSigner, mrTeeDID := getSigner(t) + _ = createSubmission(t, pRouter, definition.PresentationDefinition.ID, authorDID.DID.ID, VerifiableCredential( WithCredentialSubject(credential.CredentialSubject{ "additionalName": "Mr. T", "dateOfBirth": "1999-01-02", @@ -663,9 +663,9 @@ func TestPresentationAPI(t *testing.T) { var listSubmissionResponse router.ListSubmissionResponse err := json.NewDecoder(w.Body).Decode(&listSubmissionResponse) - assert.NoError(tttt, err) - assert.NotEmpty(tttt, listSubmissionResponse.NextPageToken) - assert.Len(tttt, listSubmissionResponse.Submissions, 1) + assert.NoError(t, err) + assert.NotEmpty(t, listSubmissionResponse.NextPageToken) + assert.Len(t, listSubmissionResponse.Submissions, 1) w = httptest.NewRecorder() params["pageToken"] = []string{listSubmissionResponse.NextPageToken} @@ -674,18 +674,18 @@ func TestPresentationAPI(t *testing.T) { c = newRequestContext(w, req) pRouter.ListSubmissions(c) - assert.Equal(tttt, http.StatusBadRequest, w.Result().StatusCode) - assert.Contains(tttt, w.Body.String(), "page token must be for the same query") + assert.Equal(t, http.StatusBadRequest, w.Result().StatusCode) + assert.Contains(t, w.Body.String(), "page token must be for the same query") }) - ttt.Run("List submissions returns many submissions", func(tttt *testing.T) { - s := test.ServiceStorage(tttt) - pRouter, didService := setupPresentationRouter(tttt, s) - authorDID := createDID(tttt, didService) + t.Run("List submissions returns many submissions", func(t *testing.T) { + s := test.ServiceStorage(t) + pRouter, didService := setupPresentationRouter(t, s) + authorDID := createDID(t, didService) - holderSigner, holderDID := getSigner(tttt) - definition := createPresentationDefinition(tttt, pRouter) - op := createSubmission(tttt, pRouter, definition.PresentationDefinition.ID, authorDID.DID.ID, VerifiableCredential( + holderSigner, holderDID := getSigner(t) + definition := createPresentationDefinition(t, pRouter) + op := createSubmission(t, pRouter, definition.PresentationDefinition.ID, authorDID.DID.ID, VerifiableCredential( WithCredentialSubject(credential.CredentialSubject{ "additionalName": "McLovin", "dateOfBirth": "1987-01-02", @@ -694,8 +694,8 @@ func TestPresentationAPI(t *testing.T) { "id": "did:web:andresuribe.com", })), holderDID, holderSigner) - mrTeeSigner, mrTeeDID := getSigner(tttt) - op2 := createSubmission(tttt, pRouter, definition.PresentationDefinition.ID, authorDID.DID.ID, VerifiableCredential( + mrTeeSigner, mrTeeDID := getSigner(t) + op2 := createSubmission(t, pRouter, definition.PresentationDefinition.ID, authorDID.DID.ID, VerifiableCredential( WithCredentialSubject(credential.CredentialSubject{ "additionalName": "Mr. T", "dateOfBirth": "1999-01-02", @@ -708,11 +708,11 @@ func TestPresentationAPI(t *testing.T) { c := newRequestContext(w, req) pRouter.ListSubmissions(c) - assert.True(tttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.ListSubmissionResponse - assert.NoError(tttt, json.NewDecoder(w.Body).Decode(&resp)) - assert.Len(tttt, resp.Submissions, 2) + assert.NoError(t, json.NewDecoder(w.Body).Decode(&resp)) + assert.Len(t, resp.Submissions, 2) expectedSubmissions := []model.Submission{ { @@ -739,12 +739,12 @@ func TestPresentationAPI(t *testing.T) { }), ) if diff != "" { - tttt.Errorf("Mismatch on submissions (-want +got):\n%s", diff) + t.Errorf("Mismatch on submissions (-want +got):\n%s", diff) } - assert.Len(tttt, resp.Submissions[0].VerifiablePresentation.VerifiableCredential, 1) - assert.Len(tttt, resp.Submissions[1].VerifiablePresentation.VerifiableCredential, 1) + assert.Len(t, resp.Submissions[0].VerifiablePresentation.VerifiableCredential, 1) + assert.Len(t, resp.Submissions[1].VerifiablePresentation.VerifiableCredential, 1) - assert.ElementsMatch(tttt, + assert.ElementsMatch(t, []string{ opstorage.StatusObjectID(op.ID), opstorage.StatusObjectID(op2.ID)}, @@ -752,7 +752,7 @@ func TestPresentationAPI(t *testing.T) { resp.Submissions[0].GetSubmission().ID, resp.Submissions[1].GetSubmission().ID, }) - assert.Equal(tttt, + assert.Equal(t, []string{ definition.PresentationDefinition.ID, definition.PresentationDefinition.ID, @@ -763,9 +763,9 @@ func TestPresentationAPI(t *testing.T) { }) }) - ttt.Run("bad filter returns error", func(tttt *testing.T) { - s := test.ServiceStorage(tttt) - pRouter, _ := setupPresentationRouter(tttt, s) + t.Run("bad filter returns error", func(t *testing.T) { + s := test.ServiceStorage(t) + pRouter, _ := setupPresentationRouter(t, s) query := url.QueryEscape("im a baaad filter that's trying to break a lot of stuff") req := httptest.NewRequest(http.MethodGet, fmt.Sprintf("https://ssi-service.com/v1/presentations/submissions?filter=%s", query), nil) @@ -773,17 +773,17 @@ func TestPresentationAPI(t *testing.T) { c := newRequestContextWithParams(w, req, map[string]string{"filter": query}) pRouter.ListSubmissions(c) - assert.Contains(tttt, w.Body.String(), "invalid filter") + assert.Contains(t, w.Body.String(), "invalid filter") }) - ttt.Run("List submissions filters based on status", func(tttt *testing.T) { - s := test.ServiceStorage(tttt) - pRouter, didService := setupPresentationRouter(tttt, s) - authorDID := createDID(tttt, didService) + t.Run("List submissions filters based on status", func(t *testing.T) { + s := test.ServiceStorage(t) + pRouter, didService := setupPresentationRouter(t, s) + authorDID := createDID(t, didService) - holderSigner, holderDID := getSigner(tttt) - definition := createPresentationDefinition(tttt, pRouter) - op := createSubmission(tttt, pRouter, definition.PresentationDefinition.ID, authorDID.DID.ID, VerifiableCredential( + holderSigner, holderDID := getSigner(t) + definition := createPresentationDefinition(t, pRouter) + op := createSubmission(t, pRouter, definition.PresentationDefinition.ID, authorDID.DID.ID, VerifiableCredential( WithCredentialSubject(credential.CredentialSubject{ "additionalName": "McLovin", "dateOfBirth": "1987-01-02", @@ -798,10 +798,10 @@ func TestPresentationAPI(t *testing.T) { c := newRequestContextWithParams(w, req, map[string]string{"filter": query}) pRouter.ListSubmissions(c) - assert.True(tttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.ListSubmissionResponse - assert.NoError(tttt, json.NewDecoder(w.Body).Decode(&resp)) + assert.NoError(t, json.NewDecoder(w.Body).Decode(&resp)) expectedSubmissions := []model.Submission{ { @@ -820,23 +820,23 @@ func TestPresentationAPI(t *testing.T) { }), ) if diff != "" { - tttt.Errorf("Mismatch on submissions (-want +got):\n%s", diff) + t.Errorf("Mismatch on submissions (-want +got):\n%s", diff) } - assert.Len(tttt, resp.Submissions, 1) - assert.Len(tttt, resp.Submissions[0].VerifiablePresentation.VerifiableCredential, 1) - assert.Equal(tttt, opstorage.StatusObjectID(op.ID), resp.Submissions[0].GetSubmission().ID) - assert.Equal(tttt, definition.PresentationDefinition.ID, resp.Submissions[0].GetSubmission().DefinitionID) + assert.Len(t, resp.Submissions, 1) + assert.Len(t, resp.Submissions[0].VerifiablePresentation.VerifiableCredential, 1) + assert.Equal(t, opstorage.StatusObjectID(op.ID), resp.Submissions[0].GetSubmission().ID) + assert.Equal(t, definition.PresentationDefinition.ID, resp.Submissions[0].GetSubmission().DefinitionID) }) - ttt.Run("List submissions filter returns empty when status does not match", func(tttt *testing.T) { - s := test.ServiceStorage(tttt) - pRouter, didService := setupPresentationRouter(tttt, s) - authorDID := createDID(tttt, didService) + t.Run("List submissions filter returns empty when status does not match", func(t *testing.T) { + s := test.ServiceStorage(t) + pRouter, didService := setupPresentationRouter(t, s) + authorDID := createDID(t, didService) - holderSigner, holderDID := getSigner(tttt) - definition := createPresentationDefinition(tttt, pRouter) - _ = createSubmission(tttt, pRouter, definition.PresentationDefinition.ID, authorDID.DID.ID, VerifiableCredential( + holderSigner, holderDID := getSigner(t) + definition := createPresentationDefinition(t, pRouter) + _ = createSubmission(t, pRouter, definition.PresentationDefinition.ID, authorDID.DID.ID, VerifiableCredential( WithCredentialSubject(credential.CredentialSubject{ "additionalName": "McLovin", "dateOfBirth": "1987-01-02", @@ -850,11 +850,11 @@ func TestPresentationAPI(t *testing.T) { w := httptest.NewRecorder() c := newRequestContextWithParams(w, req, map[string]string{"filter": query}) pRouter.ListSubmissions(c) - assert.True(tttt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.ListSubmissionResponse - assert.NoError(tttt, json.NewDecoder(w.Body).Decode(&resp)) - assert.Empty(tttt, resp.Submissions) + assert.NoError(t, json.NewDecoder(w.Body).Decode(&resp)) + assert.Empty(t, resp.Submissions) }) }) }) diff --git a/pkg/server/server_schema_test.go b/pkg/server/server_schema_test.go index a692cf205..aeef17d3a 100644 --- a/pkg/server/server_schema_test.go +++ b/pkg/server/server_schema_test.go @@ -24,55 +24,55 @@ import ( func TestSchemaAPI(t *testing.T) { for _, test := range testutil.TestDatabases { t.Run(test.Name, func(t *testing.T) { - t.Run("Test Create JsonSchema Schema", func(tt *testing.T) { - bolt := test.ServiceStorage(tt) - require.NotEmpty(tt, bolt) + t.Run("Test Create JsonSchema Schema", func(t *testing.T) { + bolt := test.ServiceStorage(t) + require.NotEmpty(t, bolt) - keyStoreService, _ := testKeyStoreService(tt, bolt) - didService, _ := testDIDService(tt, bolt, keyStoreService, nil) - schemaService := testSchemaRouter(tt, bolt, keyStoreService, didService) + keyStoreService, _ := testKeyStoreService(t, bolt) + didService, _ := testDIDService(t, bolt, keyStoreService, nil) + schemaService := testSchemaRouter(t, bolt, keyStoreService, didService) simpleSchema := getTestSchema() badSchemaRequest := router.CreateSchemaRequest{Schema: simpleSchema} - schemaRequestValue := newRequestValue(tt, badSchemaRequest) + schemaRequestValue := newRequestValue(t, badSchemaRequest) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/schemas", schemaRequestValue) w := httptest.NewRecorder() c := newRequestContext(w, req) schemaService.CreateSchema(c) - assert.Contains(tt, w.Body.String(), "invalid create schema request") + assert.Contains(t, w.Body.String(), "invalid create schema request") // reset the http recorder w = httptest.NewRecorder() schemaRequest := router.CreateSchemaRequest{Name: "test schema", Schema: simpleSchema} - schemaRequestValue = newRequestValue(tt, schemaRequest) + schemaRequestValue = newRequestValue(t, schemaRequest) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/schemas", schemaRequestValue) c = newRequestContext(w, req) schemaService.CreateSchema(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.CreateSchemaResponse err := json.NewDecoder(w.Body).Decode(&resp) - assert.NoError(tt, err) - assert.NotEmpty(tt, resp.ID) + assert.NoError(t, err) + assert.NotEmpty(t, resp.ID) // since the id is generated, we need to manually override it schemaRequest.Schema[schema.JSONSchemaIDProperty] = resp.Schema.ID() - assert.JSONEq(tt, schemaRequest.Schema.String(), resp.Schema.String()) - assert.Equal(tt, schema.JSONSchemaType, resp.Type) - assert.Empty(tt, resp.CredentialSchema) - assert.NotEmpty(tt, resp.Schema) + assert.JSONEq(t, schemaRequest.Schema.String(), resp.Schema.String()) + assert.Equal(t, schema.JSONSchemaType, resp.Type) + assert.Empty(t, resp.CredentialSchema) + assert.NotEmpty(t, resp.Schema) }) - t.Run("Test Create JsonCredentialSchema Schema", func(tt *testing.T) { - bolt := test.ServiceStorage(tt) - require.NotEmpty(tt, bolt) + t.Run("Test Create JsonCredentialSchema Schema", func(t *testing.T) { + bolt := test.ServiceStorage(t) + require.NotEmpty(t, bolt) - keyStoreService, _ := testKeyStoreService(tt, bolt) - didService, _ := testDIDService(tt, bolt, keyStoreService, nil) - schemaService := testSchemaRouter(tt, bolt, keyStoreService, didService) + keyStoreService, _ := testKeyStoreService(t, bolt) + didService, _ := testDIDService(t, bolt, keyStoreService, nil) + schemaService := testSchemaRouter(t, bolt, keyStoreService, didService) simpleSchema := getTestSchema() badSchemaRequest := router.CreateSchemaRequest{ @@ -82,13 +82,13 @@ func TestSchemaAPI(t *testing.T) { Issuer: "issuer", }, } - schemaRequestValue := newRequestValue(tt, badSchemaRequest) + schemaRequestValue := newRequestValue(t, badSchemaRequest) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/schemas", schemaRequestValue) w := httptest.NewRecorder() c := newRequestContext(w, req) schemaService.CreateSchema(c) - assert.Contains(tt, w.Body.String(), "verificationMethodId is a required field") + assert.Contains(t, w.Body.String(), "verificationMethodId is a required field") // reset the http recorder w = httptest.NewRecorder() @@ -111,52 +111,52 @@ func TestSchemaAPI(t *testing.T) { VerificationMethodID: verificationMethodID, }, } - schemaRequestValue = newRequestValue(tt, schemaRequest) + schemaRequestValue = newRequestValue(t, schemaRequest) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/schemas", schemaRequestValue) c = newRequestContext(w, req) schemaService.CreateSchema(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.CreateSchemaResponse err = json.NewDecoder(w.Body).Decode(&resp) - assert.NoError(tt, err) - assert.NotEmpty(tt, resp.ID) + assert.NoError(t, err) + assert.NotEmpty(t, resp.ID) - assert.Empty(tt, resp.Schema) - assert.NotEmpty(tt, resp.CredentialSchema) - assert.Equal(tt, schema.JSONSchemaCredentialType, resp.Type) + assert.Empty(t, resp.Schema) + assert.NotEmpty(t, resp.CredentialSchema) + assert.Equal(t, schema.JSONSchemaCredentialType, resp.Type) // decode the schema from the response and verify it _, _, cred, err := parsing.ToCredential(resp.CredentialSchema.String()) - assert.NoError(tt, err) + assert.NoError(t, err) credSubjectBytes, err := json.Marshal(cred.CredentialSubject[credential.VerifiableCredentialJSONSchemaProperty]) - assert.NoError(tt, err) + assert.NoError(t, err) var s schema.JSONSchema err = json.Unmarshal(credSubjectBytes, &s) - assert.NoError(tt, err) - assert.Equal(tt, schemaRequest.Issuer, cred.Issuer) + assert.NoError(t, err) + assert.Equal(t, schemaRequest.Issuer, cred.Issuer) // since the id is generated, we need to manually override it schemaRequest.Schema[schema.JSONSchemaIDProperty] = s.ID() delete(s, schema.JSONSchemaAdditionalIDProperty) - assert.JSONEq(tt, schemaRequest.Schema.String(), s.String()) + assert.JSONEq(t, schemaRequest.Schema.String(), s.String()) }) - t.Run("Test Get Schema and Get Schemas", func(tt *testing.T) { - bolt := test.ServiceStorage(tt) - require.NotEmpty(tt, bolt) + t.Run("Test Get Schema and Get Schemas", func(t *testing.T) { + bolt := test.ServiceStorage(t) + require.NotEmpty(t, bolt) - keyStoreService, _ := testKeyStoreService(tt, bolt) - didService, _ := testDIDService(tt, bolt, keyStoreService, nil) - schemaService := testSchemaRouter(tt, bolt, keyStoreService, didService) + keyStoreService, _ := testKeyStoreService(t, bolt) + didService, _ := testDIDService(t, bolt, keyStoreService, nil) + schemaService := testSchemaRouter(t, bolt, keyStoreService, didService) // get schema that doesn't exist w := httptest.NewRecorder() req := httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/schemas/bad", nil) c := newRequestContext(w, req) schemaService.GetSchema(c) - assert.Contains(tt, w.Body.String(), "cannot get schema without ID parameter") + assert.Contains(t, w.Body.String(), "cannot get schema without ID parameter") // reset recorder between calls w = httptest.NewRecorder() @@ -165,7 +165,7 @@ func TestSchemaAPI(t *testing.T) { req = httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/schemas/bad", nil) c = newRequestContextWithParams(w, req, map[string]string{"id": "bad"}) schemaService.GetSchema(c) - assert.Contains(tt, w.Body.String(), "could not get schema with id: bad") + assert.Contains(t, w.Body.String(), "could not get schema with id: bad") // reset recorder between calls w = httptest.NewRecorder() @@ -174,12 +174,12 @@ func TestSchemaAPI(t *testing.T) { req = httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/schemas", nil) c = newRequestContext(w, req) schemaService.ListSchemas(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var getSchemasResp router.ListSchemasResponse err := json.NewDecoder(w.Body).Decode(&getSchemasResp) - assert.NoError(tt, err) - assert.Len(tt, getSchemasResp.Schemas, 0) + assert.NoError(t, err) + assert.Len(t, getSchemasResp.Schemas, 0) // reset recorder between calls w = httptest.NewRecorder() @@ -188,22 +188,22 @@ func TestSchemaAPI(t *testing.T) { simpleSchema := getTestSchema() schemaRequest := router.CreateSchemaRequest{Name: "test schema", Schema: simpleSchema} - schemaRequestValue := newRequestValue(tt, schemaRequest) + schemaRequestValue := newRequestValue(t, schemaRequest) createReq := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/schemas", schemaRequestValue) c = newRequestContext(w, createReq) schemaService.CreateSchema(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var createResp router.CreateSchemaResponse err = json.NewDecoder(w.Body).Decode(&createResp) - assert.NoError(tt, err) + assert.NoError(t, err) - assert.NotEmpty(tt, createResp.ID) + assert.NotEmpty(t, createResp.ID) // since the id is generated, we need to manually override it schemaRequest.Schema[schema.JSONSchemaIDProperty] = createResp.Schema.ID() - assert.JSONEq(tt, schemaRequest.Schema.String(), createResp.Schema.String()) + assert.JSONEq(t, schemaRequest.Schema.String(), createResp.Schema.String()) // reset recorder between calls w = httptest.NewRecorder() @@ -212,14 +212,14 @@ func TestSchemaAPI(t *testing.T) { req = httptest.NewRequest(http.MethodGet, fmt.Sprintf("https://ssi-service.com/v1/schemas/%s", createResp.ID), nil) c = newRequestContextWithParams(w, req, map[string]string{"id": createResp.ID}) schemaService.GetSchema(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var gotSchemaResp router.GetSchemaResponse err = json.NewDecoder(w.Body).Decode(&gotSchemaResp) - assert.NoError(tt, err) + assert.NoError(t, err) - assert.Contains(tt, gotSchemaResp.Schema.ID(), createResp.ID) - assert.Equal(tt, createResp.Schema.Schema(), gotSchemaResp.Schema.Schema()) + assert.Contains(t, gotSchemaResp.Schema.ID(), createResp.ID) + assert.Equal(t, createResp.Schema.Schema(), gotSchemaResp.Schema.Schema()) // reset recorder between calls w = httptest.NewRecorder() @@ -228,20 +228,20 @@ func TestSchemaAPI(t *testing.T) { req = httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/schemas", nil) c = newRequestContext(w, req) schemaService.ListSchemas(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) err = json.NewDecoder(w.Body).Decode(&getSchemasResp) - assert.NoError(tt, err) - assert.Len(tt, getSchemasResp.Schemas, 1) + assert.NoError(t, err) + assert.Len(t, getSchemasResp.Schemas, 1) }) - t.Run("Test Delete Schema", func(tt *testing.T) { - bolt := test.ServiceStorage(tt) - require.NotEmpty(tt, bolt) + t.Run("Test Delete Schema", func(t *testing.T) { + bolt := test.ServiceStorage(t) + require.NotEmpty(t, bolt) - keyStoreService, _ := testKeyStoreService(tt, bolt) - didService, _ := testDIDService(tt, bolt, keyStoreService, nil) - schemaService := testSchemaRouter(tt, bolt, keyStoreService, didService) + keyStoreService, _ := testKeyStoreService(t, bolt) + didService, _ := testDIDService(t, bolt, keyStoreService, nil) + schemaService := testSchemaRouter(t, bolt, keyStoreService, didService) w := httptest.NewRecorder() @@ -249,48 +249,48 @@ func TestSchemaAPI(t *testing.T) { req := httptest.NewRequest(http.MethodDelete, "https://ssi-service.com/v1/schemas/bad", nil) c := newRequestContextWithParams(w, req, map[string]string{"id": "bad"}) schemaService.DeleteSchema(c) - assert.Contains(tt, w.Body.String(), "deleting schema with id: bad") + assert.Contains(t, w.Body.String(), "deleting schema with id: bad") // create a schema simpleSchema := getTestSchema() schemaRequest := router.CreateSchemaRequest{Name: "test schema", Schema: simpleSchema} - schemaRequestValue := newRequestValue(tt, schemaRequest) + schemaRequestValue := newRequestValue(t, schemaRequest) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/schemas", schemaRequestValue) w = httptest.NewRecorder() c = newRequestContext(w, req) schemaService.CreateSchema(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.CreateSchemaResponse err := json.NewDecoder(w.Body).Decode(&resp) - assert.NoError(tt, err) - assert.NotEmpty(tt, resp.ID) + assert.NoError(t, err) + assert.NotEmpty(t, resp.ID) // since the id is generated, we need to manually override it schemaRequest.Schema[schema.JSONSchemaIDProperty] = resp.Schema.ID() - assert.JSONEq(tt, schemaRequest.Schema.String(), resp.Schema.String()) + assert.JSONEq(t, schemaRequest.Schema.String(), resp.Schema.String()) // get schema by id req = httptest.NewRequest(http.MethodGet, fmt.Sprintf("https://ssi-service.com/v1/schemas/%s", resp.ID), nil) w = httptest.NewRecorder() c = newRequestContextWithParams(w, req, map[string]string{"id": resp.ID}) schemaService.GetSchema(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) // delete it req = httptest.NewRequest(http.MethodDelete, fmt.Sprintf("https://ssi-service.com/v1/schemas/%s", resp.ID), nil) w = httptest.NewRecorder() c = newRequestContextWithParams(w, req, map[string]string{"id": resp.ID}) schemaService.DeleteSchema(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) // get it back req = httptest.NewRequest(http.MethodGet, fmt.Sprintf("https://ssi-service.com/v1/schemas/%s", resp.ID), nil) w = httptest.NewRecorder() c = newRequestContextWithParams(w, req, map[string]string{"id": resp.ID}) schemaService.GetSchema(c) - assert.Contains(tt, w.Body.String(), "schema not found") + assert.Contains(t, w.Body.String(), "schema not found") }) }) } diff --git a/pkg/server/server_webhook_test.go b/pkg/server/server_webhook_test.go index 09d7229c3..29a80adcc 100644 --- a/pkg/server/server_webhook_test.go +++ b/pkg/server/server_webhook_test.go @@ -142,30 +142,30 @@ func put(t *testing.T, server *SSIServer, endpoint string, data []byte) { func TestWebhookAPI(t *testing.T) { for _, test := range testutil.TestDatabases { t.Run(test.Name, func(t *testing.T) { - t.Run("CreateWebhook returns error when missing request", func(tt *testing.T) { - db := test.ServiceStorage(tt) - require.NotEmpty(tt, db) + t.Run("CreateWebhook returns error when missing request", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - webhookRouter := testWebhookRouter(tt, db) + webhookRouter := testWebhookRouter(t, db) badWebhookRequest := router.CreateWebhookRequest{ Noun: "Credential", } - badRequestValue := newRequestValue(tt, badWebhookRequest) + badRequestValue := newRequestValue(t, badWebhookRequest) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/webhooks", badRequestValue) w := httptest.NewRecorder() c := newRequestContext(w, req) webhookRouter.CreateWebhook(c) - assert.Contains(tt, w.Body.String(), "invalid create webhook request") + assert.Contains(t, w.Body.String(), "invalid create webhook request") }) - t.Run("CreateWebhook returns error when verb is not supported", func(tt *testing.T) { - db := test.ServiceStorage(tt) - require.NotEmpty(tt, db) + t.Run("CreateWebhook returns error when verb is not supported", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - webhookRouter := testWebhookRouter(tt, db) + webhookRouter := testWebhookRouter(t, db) badWebhookRequest := router.CreateWebhookRequest{ Noun: "Credential", @@ -173,20 +173,20 @@ func TestWebhookAPI(t *testing.T) { URL: "www.abc.com", } - badRequestValue := newRequestValue(tt, badWebhookRequest) + badRequestValue := newRequestValue(t, badWebhookRequest) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/webhooks", badRequestValue) w := httptest.NewRecorder() c := newRequestContext(w, req) webhookRouter.CreateWebhook(c) - assert.Contains(tt, w.Body.String(), "invalid create webhook request") + assert.Contains(t, w.Body.String(), "invalid create webhook request") }) - t.Run("CreateWebhook returns error when url is not supported", func(tt *testing.T) { - db := test.ServiceStorage(tt) - require.NotEmpty(tt, db) + t.Run("CreateWebhook returns error when url is not supported", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - webhookRouter := testWebhookRouter(tt, db) + webhookRouter := testWebhookRouter(t, db) badWebhookRequest := router.CreateWebhookRequest{ Noun: "Credential", @@ -194,20 +194,20 @@ func TestWebhookAPI(t *testing.T) { URL: "badurl", } - badRequestValue := newRequestValue(tt, badWebhookRequest) + badRequestValue := newRequestValue(t, badWebhookRequest) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/webhooks", badRequestValue) w := httptest.NewRecorder() c := newRequestContext(w, req) webhookRouter.CreateWebhook(c) - assert.Contains(tt, w.Body.String(), "invalid create webhook request") + assert.Contains(t, w.Body.String(), "invalid create webhook request") }) - t.Run("CreateWebhook returns error when url is is missing scheme", func(tt *testing.T) { - db := test.ServiceStorage(tt) - require.NotEmpty(tt, db) + t.Run("CreateWebhook returns error when url is is missing scheme", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - webhookRouter := testWebhookRouter(tt, db) + webhookRouter := testWebhookRouter(t, db) badWebhookRequest := router.CreateWebhookRequest{ Noun: "Credential", @@ -215,20 +215,20 @@ func TestWebhookAPI(t *testing.T) { URL: "www.tbd.website", } - badRequestValue := newRequestValue(tt, badWebhookRequest) + badRequestValue := newRequestValue(t, badWebhookRequest) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/webhooks", badRequestValue) w := httptest.NewRecorder() c := newRequestContext(w, req) webhookRouter.CreateWebhook(c) - assert.Contains(tt, w.Body.String(), "invalid create webhook request") + assert.Contains(t, w.Body.String(), "invalid create webhook request") }) - t.Run("CreateWebhook returns valid response", func(tt *testing.T) { - db := test.ServiceStorage(tt) - require.NotEmpty(tt, db) + t.Run("CreateWebhook returns valid response", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - webhookRouter := testWebhookRouter(tt, db) + webhookRouter := testWebhookRouter(t, db) webhookRequest := router.CreateWebhookRequest{ Noun: "Manifest", @@ -236,20 +236,20 @@ func TestWebhookAPI(t *testing.T) { URL: "https://www.tbd.website/", } - requestValue := newRequestValue(tt, webhookRequest) + requestValue := newRequestValue(t, webhookRequest) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/webhooks", requestValue) w := httptest.NewRecorder() c := newRequestContext(w, req) webhookRouter.CreateWebhook(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) }) - t.Run("Test Happy Path Delete Webhook", func(tt *testing.T) { - db := test.ServiceStorage(tt) - require.NotEmpty(tt, db) + t.Run("Test Happy Path Delete Webhook", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - webhookRouter := testWebhookRouter(tt, db) + webhookRouter := testWebhookRouter(t, db) webhookRequest := router.CreateWebhookRequest{ Noun: "Manifest", @@ -257,29 +257,29 @@ func TestWebhookAPI(t *testing.T) { URL: "https://www.tbd.website/", } - requestValue := newRequestValue(tt, webhookRequest) + requestValue := newRequestValue(t, webhookRequest) req := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/webhooks", requestValue) w := httptest.NewRecorder() c := newRequestContext(w, req) webhookRouter.CreateWebhook(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) req = httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/webhooks", nil) w = httptest.NewRecorder() c = newRequestContext(w, req) webhookRouter.ListWebhooks(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var resp router.ListWebhooksResponse err := json.NewDecoder(w.Body).Decode(&resp) - assert.NoError(tt, err) - assert.Len(tt, resp.Webhooks, 1) + assert.NoError(t, err) + assert.Len(t, resp.Webhooks, 1) c = newRequestContext(w, req) webhookRouter.ListWebhooks(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) deleteWebhookRequest := router.DeleteWebhookRequest{ Noun: "Manifest", @@ -287,43 +287,43 @@ func TestWebhookAPI(t *testing.T) { URL: "https://www.tbd.website/", } - requestValue = newRequestValue(tt, deleteWebhookRequest) + requestValue = newRequestValue(t, deleteWebhookRequest) req = httptest.NewRequest(http.MethodDelete, "https://ssi-service.com/v1/webhooks", requestValue) w = httptest.NewRecorder() c = newRequestContext(w, req) webhookRouter.DeleteWebhook(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) req = httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/webhooks", nil) w = httptest.NewRecorder() c = newRequestContext(w, req) webhookRouter.ListWebhooks(c) - assert.True(tt, util.Is2xxResponse(w.Code)) + assert.True(t, util.Is2xxResponse(w.Code)) var respAfter router.ListWebhooksResponse err = json.NewDecoder(w.Body).Decode(&respAfter) - assert.NoError(tt, err) - assert.Len(tt, respAfter.Webhooks, 0) + assert.NoError(t, err) + assert.Len(t, respAfter.Webhooks, 0) }) - t.Run("GetWebhook Throws Error When Webhook None Exist", func(tt *testing.T) { - db := test.ServiceStorage(tt) - require.NotEmpty(tt, db) + t.Run("GetWebhook Throws Error When Webhook None Exist", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - webhookService := testWebhookService(tt, db) + webhookService := testWebhookService(t, db) wh, err := webhookService.GetWebhook(context.Background(), webhook.GetWebhookRequest{Noun: "Credential", Verb: "Create"}) - assert.ErrorContains(tt, err, "webhook does not exist") - assert.Nil(tt, wh) + assert.ErrorContains(t, err, "webhook does not exist") + assert.Nil(t, wh) }) - t.Run("GetWebhook Returns Webhook That Does Exist", func(tt *testing.T) { - db := test.ServiceStorage(tt) - require.NotEmpty(tt, db) + t.Run("GetWebhook Returns Webhook That Does Exist", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - webhookService := testWebhookService(tt, db) + webhookService := testWebhookService(t, db) webhookRequest := webhook.CreateWebhookRequest{ Noun: "Manifest", @@ -332,84 +332,84 @@ func TestWebhookAPI(t *testing.T) { } createdWebhook, err := webhookService.CreateWebhook(context.Background(), webhookRequest) - assert.NoError(tt, err) - assert.Equal(tt, createdWebhook.Webhook.Noun, webhookRequest.Noun) - assert.Equal(tt, createdWebhook.Webhook.Verb, webhookRequest.Verb) - assert.Equal(tt, createdWebhook.Webhook.URLS[0], webhookRequest.URL) + assert.NoError(t, err) + assert.Equal(t, createdWebhook.Webhook.Noun, webhookRequest.Noun) + assert.Equal(t, createdWebhook.Webhook.Verb, webhookRequest.Verb) + assert.Equal(t, createdWebhook.Webhook.URLS[0], webhookRequest.URL) getWebhookRequest := webhook.GetWebhookRequest{Noun: "Manifest", Verb: "Create"} gotWebhook, err := webhookService.GetWebhook(context.Background(), getWebhookRequest) - assert.NoError(tt, err) - assert.Equal(tt, gotWebhook.Webhook.Noun, webhookRequest.Noun) - assert.Equal(tt, gotWebhook.Webhook.Verb, webhookRequest.Verb) - assert.Equal(tt, gotWebhook.Webhook.URLS[0], webhookRequest.URL) + assert.NoError(t, err) + assert.Equal(t, gotWebhook.Webhook.Noun, webhookRequest.Noun) + assert.Equal(t, gotWebhook.Webhook.Verb, webhookRequest.Verb) + assert.Equal(t, gotWebhook.Webhook.URLS[0], webhookRequest.URL) }) - t.Run("Test Get Webhooks", func(tt *testing.T) { - db := test.ServiceStorage(tt) - require.NotEmpty(tt, db) + t.Run("Test Get Webhooks", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - webhookService := testWebhookService(tt, db) + webhookService := testWebhookService(t, db) gotWebhooks, err := webhookService.ListWebhooks(context.Background()) - assert.NoError(tt, err) - assert.Len(tt, gotWebhooks.Webhooks, 0) + assert.NoError(t, err) + assert.Len(t, gotWebhooks.Webhooks, 0) _, err = webhookService.CreateWebhook(context.Background(), webhook.CreateWebhookRequest{ Noun: "Manifest", Verb: "Create", URL: "https://www.tbd.website/", }) - assert.NoError(tt, err) + assert.NoError(t, err) _, err = webhookService.CreateWebhook(context.Background(), webhook.CreateWebhookRequest{ Noun: "Manifest", Verb: "Create", URL: "https://www.tbd.dev/", }) - assert.NoError(tt, err) + assert.NoError(t, err) _, err = webhookService.CreateWebhook(context.Background(), webhook.CreateWebhookRequest{ Noun: "Manifest", Verb: "Delete", URL: "https://www.tbd.website/", }) - assert.NoError(tt, err) + assert.NoError(t, err) gotWebhooks, err = webhookService.ListWebhooks(context.Background()) - assert.NoError(tt, err) - assert.Len(tt, gotWebhooks.Webhooks, 2) + assert.NoError(t, err) + assert.Len(t, gotWebhooks.Webhooks, 2) }) - t.Run("Test Delete Webhook", func(tt *testing.T) { - db := test.ServiceStorage(tt) - require.NotEmpty(tt, db) + t.Run("Test Delete Webhook", func(t *testing.T) { + db := test.ServiceStorage(t) + require.NotEmpty(t, db) - webhookService := testWebhookService(tt, db) + webhookService := testWebhookService(t, db) err := webhookService.DeleteWebhook(context.Background(), webhook.DeleteWebhookRequest{Noun: "Credential", Verb: "Create", URL: "https://www.tbd.website/"}) - assert.ErrorContains(tt, err, "webhook does not exist") + assert.ErrorContains(t, err, "webhook does not exist") _, err = webhookService.CreateWebhook(context.Background(), webhook.CreateWebhookRequest{ Noun: "Manifest", Verb: "Create", URL: "https://www.tbd.website/", }) - assert.NoError(tt, err) + assert.NoError(t, err) gotWebhook, err := webhookService.GetWebhook(context.Background(), webhook.GetWebhookRequest{Noun: "Manifest", Verb: "Create"}) - assert.NoError(tt, err) - assert.Equal(tt, gotWebhook.Webhook.Noun, webhook.Noun("Manifest")) - assert.Equal(tt, gotWebhook.Webhook.Verb, webhook.Verb("Create")) - assert.Equal(tt, gotWebhook.Webhook.URLS[0], "https://www.tbd.website/") + assert.NoError(t, err) + assert.Equal(t, gotWebhook.Webhook.Noun, webhook.Noun("Manifest")) + assert.Equal(t, gotWebhook.Webhook.Verb, webhook.Verb("Create")) + assert.Equal(t, gotWebhook.Webhook.URLS[0], "https://www.tbd.website/") err = webhookService.DeleteWebhook(context.Background(), webhook.DeleteWebhookRequest{Noun: "Manifest", Verb: "Create", URL: "https://www.tbd.website/"}) - assert.NoError(tt, err) + assert.NoError(t, err) gotWebhook, err = webhookService.GetWebhook(context.Background(), webhook.GetWebhookRequest{Noun: "Manifest", Verb: "Create"}) - assert.ErrorContains(tt, err, "webhook does not exist") - assert.Empty(tt, gotWebhook) + assert.ErrorContains(t, err, "webhook does not exist") + assert.Empty(t, gotWebhook) }) }) } diff --git a/pkg/service/did/ion_test.go b/pkg/service/did/ion_test.go index 11f572897..78247e666 100644 --- a/pkg/service/did/ion_test.go +++ b/pkg/service/did/ion_test.go @@ -27,47 +27,47 @@ var BasicDIDResolution []byte func TestIONHandler(t *testing.T) { for _, test := range testutil.TestDatabases { t.Run(test.Name, func(t *testing.T) { - t.Run("Create ION Handler", func(tt *testing.T) { + t.Run("Create ION Handler", func(t *testing.T) { handler, err := NewIONHandler("", nil, nil, nil, nil) - assert.Error(tt, err) - assert.Empty(tt, handler) - assert.Contains(tt, err.Error(), "baseURL cannot be empty") + assert.Error(t, err) + assert.Empty(t, handler) + assert.Contains(t, err.Error(), "baseURL cannot be empty") - s := test.ServiceStorage(tt) - keystoreService := testKeyStoreService(tt, s) + s := test.ServiceStorage(t) + keystoreService := testKeyStoreService(t, s) didStorage, err := NewDIDStorage(s) - assert.NoError(tt, err) + assert.NoError(t, err) handler, err = NewIONHandler("bad", nil, keystoreService, nil, nil) - assert.Error(tt, err) - assert.Empty(tt, handler) - assert.Contains(tt, err.Error(), "storage cannot be empty") + assert.Error(t, err) + assert.Empty(t, handler) + assert.Contains(t, err.Error(), "storage cannot be empty") handler, err = NewIONHandler("bad", didStorage, nil, nil, nil) - assert.Error(tt, err) - assert.Empty(tt, handler) - assert.Contains(tt, err.Error(), "keystore cannot be empty") + assert.Error(t, err) + assert.Empty(t, handler) + assert.Contains(t, err.Error(), "keystore cannot be empty") handler, err = NewIONHandler("bad", didStorage, keystoreService, nil, nil) - assert.Error(tt, err) - assert.Empty(tt, handler) - assert.Contains(tt, err.Error(), "invalid resolution URL") + assert.Error(t, err) + assert.Empty(t, handler) + assert.Contains(t, err.Error(), "invalid resolution URL") handler, err = NewIONHandler("https://example.com", didStorage, keystoreService, nil, nil) - assert.NoError(tt, err) - assert.NotEmpty(tt, handler) + assert.NoError(t, err) + assert.NotEmpty(t, handler) - assert.Equal(tt, handler.GetMethod(), did.IONMethod) + assert.Equal(t, handler.GetMethod(), did.IONMethod) }) - t.Run("Create DID", func(tt *testing.T) { + t.Run("Create DID", func(t *testing.T) { // create a handler - s := test.ServiceStorage(tt) - keystoreService := testKeyStoreService(tt, s) + s := test.ServiceStorage(t) + keystoreService := testKeyStoreService(t, s) didStorage, err := NewDIDStorage(s) - assert.NoError(tt, err) + assert.NoError(t, err) handler, err := NewIONHandler("https://test-ion-resolver.com", didStorage, keystoreService, nil, nil) - assert.NoError(tt, err) - assert.NotEmpty(tt, handler) + assert.NoError(t, err) + assert.NotEmpty(t, handler) gock.New("https://test-ion-resolver.com"). Post("/operations"). @@ -76,11 +76,11 @@ func TestIONHandler(t *testing.T) { defer gock.Off() publicKey, privKey, err := crypto.GenerateEd25519Key() - require.NoError(tt, err) + require.NoError(t, err) signer, err := jwx.NewJWXSigner("test-id", "test-kid", privKey) - require.NoError(tt, err) + require.NoError(t, err) jwxJWK, err := jwx.PublicKeyToPublicKeyJWK("test-kid", publicKey) - require.NoError(tt, err) + require.NoError(t, err) ionPublicKey := ion.PublicKey{ ID: "test-id", Type: "JsonWebKey2020", @@ -88,9 +88,9 @@ func TestIONHandler(t *testing.T) { Purposes: []did.PublicKeyPurpose{did.Authentication}, } ionPublicKeyData, err := json.Marshal(ionPublicKey) - require.NoError(tt, err) + require.NoError(t, err) jwsPublicKey, err := signer.SignJWS(ionPublicKeyData) - require.NoError(tt, err) + require.NoError(t, err) // create a did createDIDRequest := CreateDIDRequest{ @@ -102,30 +102,30 @@ func TestIONHandler(t *testing.T) { }, } - tt.Run("good input returns no error", func(t *testing.T) { + t.Run("good input returns no error", func(t *testing.T) { created, err := handler.CreateDID(context.Background(), createDIDRequest) - assert.NoError(tt, err) - assert.NotEmpty(tt, created) + assert.NoError(t, err) + assert.NotEmpty(t, created) }) - tt.Run("signing with another key returns error", func(ttt *testing.T) { + t.Run("signing with another key returns error", func(t *testing.T) { a := createDIDRequest _, privKey, err := crypto.GenerateEd25519Key() - require.NoError(ttt, err) + require.NoError(t, err) signer2, err := jwx.NewJWXSigner("test-id", "test-kid", privKey) - require.NoError(ttt, err) + require.NoError(t, err) signedWithOtherKey, err := signer2.SignJWS(ionPublicKeyData) - require.NoError(ttt, err) + require.NoError(t, err) a.Options.(CreateIONDIDOptions).JWSPublicKeys[0] = string(signedWithOtherKey) _, err = handler.CreateDID(context.Background(), createDIDRequest) - assert.Error(ttt, err) - assert.ErrorContains(ttt, err, "verifying JWS for") + assert.Error(t, err) + assert.ErrorContains(t, err, "verifying JWS for") }) }) - t.Run("Get a Created DID", func(tt *testing.T) { + t.Run("Get a Created DID", func(t *testing.T) { gock.New("https://ion.tbddev.org"). Post("/operations"). Reply(200). @@ -133,40 +133,40 @@ func TestIONHandler(t *testing.T) { defer gock.Off() // create a handler - s := test.ServiceStorage(tt) - keystoreService := testKeyStoreService(tt, s) + s := test.ServiceStorage(t) + keystoreService := testKeyStoreService(t, s) didStorage, err := NewDIDStorage(s) - assert.NoError(tt, err) + assert.NoError(t, err) handler, err := NewIONHandler("https://ion.tbddev.org", didStorage, keystoreService, nil, nil) - assert.NoError(tt, err) - assert.NotEmpty(tt, handler) + assert.NoError(t, err) + assert.NotEmpty(t, handler) // create a did created, err := handler.CreateDID(context.Background(), CreateDIDRequest{ Method: did.IONMethod, KeyType: crypto.Ed25519, }) - assert.NoError(tt, err) - assert.NotEmpty(tt, created) + assert.NoError(t, err) + assert.NotEmpty(t, created) // get the did gotDID, err := handler.GetDID(context.Background(), GetDIDRequest{ Method: did.IONMethod, ID: created.DID.ID, }) - assert.NoError(tt, err) - assert.NotEmpty(tt, gotDID) + assert.NoError(t, err) + assert.NotEmpty(t, gotDID) }) - t.Run("Get DID from storage", func(tt *testing.T) { + t.Run("Get DID from storage", func(t *testing.T) { // create a handler - s := test.ServiceStorage(tt) - keystoreService := testKeyStoreService(tt, s) + s := test.ServiceStorage(t) + keystoreService := testKeyStoreService(t, s) didStorage, err := NewDIDStorage(s) - assert.NoError(tt, err) + assert.NoError(t, err) handler, err := NewIONHandler("https://test-ion-resolver.com", didStorage, keystoreService, nil, nil) - assert.NoError(tt, err) - assert.NotEmpty(tt, handler) + assert.NoError(t, err) + assert.NotEmpty(t, handler) gock.New("https://test-ion-resolver.com"). Post("/operations"). @@ -179,8 +179,8 @@ func TestIONHandler(t *testing.T) { Method: did.IONMethod, KeyType: crypto.Ed25519, }) - assert.NoError(tt, err) - assert.NotEmpty(tt, created) + assert.NoError(t, err) + assert.NotEmpty(t, created) gock.New("https://test-ion-resolver.com"). Get("/identifiers/" + created.DID.ID). @@ -192,20 +192,20 @@ func TestIONHandler(t *testing.T) { Method: did.IONMethod, ID: created.DID.ID, }) - assert.NoError(tt, err) - assert.NotEmpty(tt, gotDID) - assert.Equal(tt, created.DID.ID, gotDID.DID.ID) + assert.NoError(t, err) + assert.NotEmpty(t, gotDID) + assert.Equal(t, created.DID.ID, gotDID.DID.ID) }) - t.Run("Get DIDs from storage", func(tt *testing.T) { + t.Run("Get DIDs from storage", func(t *testing.T) { // create a handler - s := test.ServiceStorage(tt) - keystoreService := testKeyStoreService(tt, s) + s := test.ServiceStorage(t) + keystoreService := testKeyStoreService(t, s) didStorage, err := NewDIDStorage(s) - assert.NoError(tt, err) + assert.NoError(t, err) handler, err := NewIONHandler("https://test-ion-resolver.com", didStorage, keystoreService, nil, nil) - assert.NoError(tt, err) - assert.NotEmpty(tt, handler) + assert.NoError(t, err) + assert.NotEmpty(t, handler) gock.New("https://test-ion-resolver.com"). Post("/operations"). @@ -218,11 +218,11 @@ func TestIONHandler(t *testing.T) { Method: did.IONMethod, KeyType: crypto.Ed25519, }) - assert.NoError(tt, err) - assert.NotEmpty(tt, created) + assert.NoError(t, err) + assert.NotEmpty(t, created) createdDIDData, err := json.Marshal(created.DID) - assert.NoError(tt, err) + assert.NoError(t, err) gock.New("https://test-ion-resolver.com"). Get("/identifiers/" + created.DID.ID). @@ -231,39 +231,39 @@ func TestIONHandler(t *testing.T) { // get all DIDs gotDIDs, err := handler.ListDIDs(context.Background(), nil) - assert.NoError(tt, err) - assert.NotEmpty(tt, gotDIDs) - assert.Len(tt, gotDIDs.DIDs, 1) + assert.NoError(t, err) + assert.NotEmpty(t, gotDIDs) + assert.Len(t, gotDIDs.DIDs, 1) // delete a did err = handler.SoftDeleteDID(context.Background(), DeleteDIDRequest{ Method: did.IONMethod, ID: created.DID.ID, }) - assert.NoError(tt, err) + assert.NoError(t, err) // get all DIDs after deleting gotDIDsAfterDelete, err := handler.ListDIDs(context.Background(), nil) - assert.NoError(tt, err) - assert.NotEmpty(tt, gotDIDs) - assert.Len(tt, gotDIDsAfterDelete.DIDs, 0) + assert.NoError(t, err) + assert.NotEmpty(t, gotDIDs) + assert.Len(t, gotDIDsAfterDelete.DIDs, 0) // get all deleted DIDs after delete gotDeletedDIDs, err := handler.ListDeletedDIDs(context.Background()) - assert.NoError(tt, err) - assert.NotEmpty(tt, gotDIDs) - assert.Len(tt, gotDeletedDIDs.DIDs, 1) + assert.NoError(t, err) + assert.NotEmpty(t, gotDIDs) + assert.Len(t, gotDeletedDIDs.DIDs, 1) }) - t.Run("Get DID from resolver", func(tt *testing.T) { + t.Run("Get DID from resolver", func(t *testing.T) { // create a handler - s := test.ServiceStorage(tt) - keystoreService := testKeyStoreService(tt, s) + s := test.ServiceStorage(t) + keystoreService := testKeyStoreService(t, s) didStorage, err := NewDIDStorage(s) - assert.NoError(tt, err) + assert.NoError(t, err) handler, err := NewIONHandler("https://test-ion-resolver.com", didStorage, keystoreService, nil, nil) - assert.NoError(tt, err) - assert.NotEmpty(tt, handler) + assert.NoError(t, err) + assert.NotEmpty(t, handler) gock.New("https://test-ion-resolver.com"). Get("/identifiers/did:ion:test"). @@ -276,9 +276,9 @@ func TestIONHandler(t *testing.T) { Method: did.IONMethod, ID: "did:ion:test", }) - assert.NoError(tt, err) - assert.NotEmpty(tt, gotDID) - assert.Equal(tt, "did:ion:test", gotDID.DID.ID) + assert.NoError(t, err) + assert.NotEmpty(t, gotDID) + assert.Equal(t, "did:ion:test", gotDID.DID.ID) }) }) } diff --git a/pkg/service/did/resolution/universal_test.go b/pkg/service/did/resolution/universal_test.go index fc92f4fe2..cf4e4ee72 100644 --- a/pkg/service/did/resolution/universal_test.go +++ b/pkg/service/did/resolution/universal_test.go @@ -11,25 +11,25 @@ import ( // TestUniversalResolver tests the universal resolver's dev instance. It is intentionally skipped to not run in CI. func TestUniversalResolver(t *testing.T) { t.Skip("skipping integration test") - t.Run("test get methods", func(tt *testing.T) { + t.Run("test get methods", func(t *testing.T) { resolver, err := newUniversalResolver("https://dev.uniresolver.io") - assert.NoError(tt, err) - assert.NotEmpty(tt, resolver) + assert.NoError(t, err) + assert.NotEmpty(t, resolver) methods := resolver.Methods() - assert.NotEmpty(tt, methods) - assert.Contains(tt, methods, didsdk.Method("ion")) + assert.NotEmpty(t, methods) + assert.Contains(t, methods, didsdk.Method("ion")) }) - t.Run("test get ion resolution", func(tt *testing.T) { + t.Run("test get ion resolution", func(t *testing.T) { resolver, err := newUniversalResolver("https://dev.uniresolver.io") - assert.NoError(tt, err) - assert.NotEmpty(tt, resolver) + assert.NoError(t, err) + assert.NotEmpty(t, resolver) resolution, err := resolver.Resolve(context.Background(), "did:ion:EiClkZMDxPKqC9c-umQfTkR8vvZ9JPhl_xLDI9Nfk38w5w") - assert.NoError(tt, err) - assert.NotEmpty(tt, resolution) + assert.NoError(t, err) + assert.NotEmpty(t, resolution) - assert.Equal(tt, "did:ion:EiClkZMDxPKqC9c-umQfTkR8vvZ9JPhl_xLDI9Nfk38w5w", resolution.Document.ID) + assert.Equal(t, "did:ion:EiClkZMDxPKqC9c-umQfTkR8vvZ9JPhl_xLDI9Nfk38w5w", resolution.Document.ID) }) } diff --git a/pkg/service/did/storage_test.go b/pkg/service/did/storage_test.go index 4491c9f44..4a9bfcf08 100644 --- a/pkg/service/did/storage_test.go +++ b/pkg/service/did/storage_test.go @@ -13,9 +13,9 @@ func TestStorage(t *testing.T) { for _, test := range testutil.TestDatabases { t.Run(test.Name, func(t *testing.T) { - t.Run("Create bad DID - no namespace", func(tt *testing.T) { - ds, err := NewDIDStorage(test.ServiceStorage(tt)) - assert.NoError(tt, err) + t.Run("Create bad DID - no namespace", func(t *testing.T) { + ds, err := NewDIDStorage(test.ServiceStorage(t)) + assert.NoError(t, err) // create a did toStore := DefaultStoredDID{ @@ -28,35 +28,35 @@ func TestStorage(t *testing.T) { // store err = ds.StoreDID(context.Background(), toStore) - assert.Error(tt, err) - assert.Contains(tt, err.Error(), "could not store DID") + assert.Error(t, err) + assert.Contains(t, err.Error(), "could not store DID") }) - t.Run("Get bad DID - namespace does not exist", func(tt *testing.T) { - ds, err := NewDIDStorage(test.ServiceStorage(tt)) - assert.NoError(tt, err) + t.Run("Get bad DID - namespace does not exist", func(t *testing.T) { + ds, err := NewDIDStorage(test.ServiceStorage(t)) + assert.NoError(t, err) // store gotDID, err := ds.GetDIDDefault(context.Background(), "did:test:bad") - assert.Error(tt, err) - assert.Empty(tt, gotDID) - assert.Contains(tt, err.Error(), "could not get DID: did:test:bad: no namespace found for DID method: test") + assert.Error(t, err) + assert.Empty(t, gotDID) + assert.Contains(t, err.Error(), "could not get DID: did:test:bad: no namespace found for DID method: test") }) - t.Run("Get bad DID - does not exist", func(tt *testing.T) { - ds, err := NewDIDStorage(test.ServiceStorage(tt)) - assert.NoError(tt, err) + t.Run("Get bad DID - does not exist", func(t *testing.T) { + ds, err := NewDIDStorage(test.ServiceStorage(t)) + assert.NoError(t, err) // store gotDID, err := ds.GetDIDDefault(context.Background(), "did:key:bad") - assert.Error(tt, err) - assert.Empty(tt, gotDID) - assert.Contains(tt, err.Error(), "could not get DID: did:key:bad") + assert.Error(t, err) + assert.Empty(t, gotDID) + assert.Contains(t, err.Error(), "could not get DID: did:key:bad") }) - t.Run("Create and Get DID", func(tt *testing.T) { - ds, err := NewDIDStorage(test.ServiceStorage(tt)) - assert.NoError(tt, err) + t.Run("Create and Get DID", func(t *testing.T) { + ds, err := NewDIDStorage(test.ServiceStorage(t)) + assert.NoError(t, err) // create a did toStore := DefaultStoredDID{ @@ -69,23 +69,23 @@ func TestStorage(t *testing.T) { // store err = ds.StoreDID(context.Background(), toStore) - assert.NoError(tt, err) + assert.NoError(t, err) // get it back as a default got, err := ds.GetDIDDefault(context.Background(), "did:key:test") - assert.NoError(tt, err) - assert.Equal(tt, toStore, *got) + assert.NoError(t, err) + assert.Equal(t, toStore, *got) // get it back as a did outDID := new(DefaultStoredDID) err = ds.GetDID(context.Background(), "did:key:test", outDID) - assert.NoError(tt, err) - assert.Equal(tt, toStore, *outDID) + assert.NoError(t, err) + assert.Equal(t, toStore, *outDID) }) - t.Run("Create and Get DID of a custom type", func(tt *testing.T) { - ds, err := NewDIDStorage(test.ServiceStorage(tt)) - assert.NoError(tt, err) + t.Run("Create and Get DID of a custom type", func(t *testing.T) { + ds, err := NewDIDStorage(test.ServiceStorage(t)) + assert.NoError(t, err) // create a did toStore := customStoredDID{ @@ -95,23 +95,23 @@ func TestStorage(t *testing.T) { // store err = ds.StoreDID(context.Background(), toStore) - assert.NoError(tt, err) + assert.NoError(t, err) // get it back as a default - which won't be equal got, err := ds.GetDIDDefault(context.Background(), "did:key:test") - assert.NoError(tt, err) - assert.NotEqual(tt, toStore, *got) + assert.NoError(t, err) + assert.NotEqual(t, toStore, *got) // get it back as a custom did outDID := new(customStoredDID) err = ds.GetDID(context.Background(), "did:key:test", outDID) - assert.NoError(tt, err) - assert.Equal(tt, toStore, *outDID) + assert.NoError(t, err) + assert.Equal(t, toStore, *outDID) }) - t.Run("Create and Get Multiple DIDs", func(tt *testing.T) { - ds, err := NewDIDStorage(test.ServiceStorage(tt)) - assert.NoError(tt, err) + t.Run("Create and Get Multiple DIDs", func(t *testing.T) { + ds, err := NewDIDStorage(test.ServiceStorage(t)) + assert.NoError(t, err) // create two dids toStore1 := DefaultStoredDID{ @@ -132,29 +132,29 @@ func TestStorage(t *testing.T) { // store err = ds.StoreDID(context.Background(), toStore1) - assert.NoError(tt, err) + assert.NoError(t, err) err = ds.StoreDID(context.Background(), toStore2) - assert.NoError(tt, err) + assert.NoError(t, err) // get both back as default got, err := ds.ListDIDsDefault(context.Background(), didsdk.KeyMethod.String()) - assert.NoError(tt, err) - assert.Len(tt, got, 2) - assert.Contains(tt, got, toStore1) - assert.Contains(tt, got, toStore2) + assert.NoError(t, err) + assert.Len(t, got, 2) + assert.Contains(t, got, toStore1) + assert.Contains(t, got, toStore2) // get back as did gotDIDs, err := ds.ListDIDs(context.Background(), didsdk.KeyMethod.String(), new(DefaultStoredDID)) - assert.NoError(tt, err) - assert.Len(tt, gotDIDs, 2) - assert.Contains(tt, gotDIDs, &toStore1) - assert.Contains(tt, gotDIDs, &toStore2) + assert.NoError(t, err) + assert.Len(t, gotDIDs, 2) + assert.Contains(t, gotDIDs, &toStore1) + assert.Contains(t, gotDIDs, &toStore2) }) - t.Run("Soft delete DID", func(tt *testing.T) { - ds, err := NewDIDStorage(test.ServiceStorage(tt)) - assert.NoError(tt, err) + t.Run("Soft delete DID", func(t *testing.T) { + ds, err := NewDIDStorage(test.ServiceStorage(t)) + assert.NoError(t, err) // create two dids toStore1 := DefaultStoredDID{ @@ -175,30 +175,30 @@ func TestStorage(t *testing.T) { // store err = ds.StoreDID(context.Background(), toStore1) - assert.NoError(tt, err) + assert.NoError(t, err) err = ds.StoreDID(context.Background(), toStore2) - assert.NoError(tt, err) + assert.NoError(t, err) // get both and verify there are two gotDIDs, err := ds.ListDIDsDefault(context.Background(), didsdk.KeyMethod.String()) - assert.NoError(tt, err) - assert.Len(tt, gotDIDs, 2) + assert.NoError(t, err) + assert.Len(t, gotDIDs, 2) // soft delete one err = ds.DeleteDID(context.Background(), "did:key:test-1") - assert.NoError(tt, err) + assert.NoError(t, err) // get it back _, err = ds.GetDIDDefault(context.Background(), "did:key:test-1") - assert.Error(tt, err) - assert.Contains(tt, err.Error(), "could not get DID: did:key:test-1") + assert.Error(t, err) + assert.Contains(t, err.Error(), "could not get DID: did:key:test-1") // get both and verify there is one gotDIDs, err = ds.ListDIDsDefault(context.Background(), didsdk.KeyMethod.String()) - assert.NoError(tt, err) - assert.Len(tt, gotDIDs, 1) - assert.Contains(tt, gotDIDs, toStore2) + assert.NoError(t, err) + assert.Len(t, gotDIDs, 1) + assert.Contains(t, gotDIDs, toStore2) }) }) }