This repository has been archived by the owner on Dec 12, 2024. It is now read-only.
generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding credential revocation * updating config and refactor * remove suspended Co-authored-by: Gabe <[email protected]>
- Loading branch information
1 parent
114818b
commit 3723d02
Showing
14 changed files
with
1,056 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,10 +40,17 @@ func TestCredentialRouter(t *testing.T) { | |
}) | ||
|
||
t.Run("Credential Service Test", func(tt *testing.T) { | ||
|
||
bolt, err := storage.NewBoltDB() | ||
assert.NoError(tt, err) | ||
assert.NotEmpty(tt, bolt) | ||
|
||
// remove the db file after the test | ||
tt.Cleanup(func() { | ||
_ = bolt.Close() | ||
_ = os.Remove(storage.DBFile) | ||
}) | ||
|
||
serviceConfig := config.CredentialServiceConfig{BaseServiceConfig: &config.BaseServiceConfig{Name: "credential"}} | ||
keyStoreService := testKeyStoreService(tt, bolt) | ||
didService := testDIDService(tt, bolt, keyStoreService) | ||
|
@@ -194,4 +201,97 @@ func TestCredentialRouter(t *testing.T) { | |
assert.Error(tt, err) | ||
assert.Contains(tt, err.Error(), fmt.Sprintf("credential not found with id: %s", cred.ID)) | ||
}) | ||
|
||
t.Run("Credential Status List Test", func(tt *testing.T) { | ||
bolt, err := storage.NewBoltDB() | ||
assert.NoError(tt, err) | ||
assert.NotEmpty(tt, bolt) | ||
|
||
// remove the db file after the test | ||
tt.Cleanup(func() { | ||
_ = bolt.Close() | ||
_ = os.Remove(storage.DBFile) | ||
}) | ||
|
||
serviceConfig := config.CredentialServiceConfig{BaseServiceConfig: &config.BaseServiceConfig{Name: "credential"}} | ||
keyStoreService := testKeyStoreService(tt, bolt) | ||
didService := testDIDService(tt, bolt, keyStoreService) | ||
schemaService := testSchemaService(tt, bolt, keyStoreService, didService) | ||
credService, err := credential.NewCredentialService(serviceConfig, bolt, keyStoreService, didService.GetResolver(), schemaService) | ||
assert.NoError(tt, err) | ||
assert.NotEmpty(tt, credService) | ||
|
||
// check type and status | ||
assert.Equal(tt, framework.Credential, credService.Type()) | ||
assert.Equal(tt, framework.StatusReady, credService.Status().Status) | ||
|
||
// create a did | ||
issuerDID, err := didService.CreateDIDByMethod(did.CreateDIDRequest{Method: didsdk.KeyMethod, KeyType: crypto.Ed25519}) | ||
assert.NoError(tt, err) | ||
assert.NotEmpty(tt, issuerDID) | ||
|
||
// create a schema | ||
emailSchema := map[string]interface{}{ | ||
"type": "object", | ||
"properties": map[string]interface{}{ | ||
"email": map[string]interface{}{ | ||
"type": "string", | ||
}, | ||
}, | ||
"required": []interface{}{"email"}, | ||
"additionalProperties": false, | ||
} | ||
|
||
createdSchema, err := schemaService.CreateSchema(schema.CreateSchemaRequest{Author: "me", Name: "simple schema", Schema: emailSchema}) | ||
assert.NoError(tt, err) | ||
assert.NotEmpty(tt, createdSchema) | ||
|
||
issuer := issuerDID.DID.ID | ||
subject := "did:test:345" | ||
|
||
createdCred, err := credService.CreateCredential(credential.CreateCredentialRequest{ | ||
Issuer: issuer, | ||
Subject: subject, | ||
JSONSchema: createdSchema.ID, | ||
Data: map[string]interface{}{ | ||
"email": "[email protected]", | ||
}, | ||
Expiry: time.Now().Add(24 * time.Hour).Format(time.RFC3339), | ||
Revocable: true, | ||
}) | ||
|
||
assert.NoError(tt, err) | ||
assert.NotEmpty(tt, createdCred) | ||
assert.NotEmpty(tt, createdCred.CredentialJWT) | ||
|
||
credStatusMap, ok := createdCred.Credential.CredentialStatus.(map[string]interface{}) | ||
assert.True(tt, ok) | ||
|
||
assert.Contains(tt, credStatusMap["id"], fmt.Sprintf("v1/credentials/%s/status", createdCred.ID)) | ||
assert.Contains(tt, credStatusMap["statusListCredential"], "v1/credentials/status") | ||
assert.NotEmpty(tt, credStatusMap["statusListIndex"]) | ||
|
||
createdCredTwo, err := credService.CreateCredential(credential.CreateCredentialRequest{ | ||
Issuer: issuer, | ||
Subject: subject, | ||
JSONSchema: createdSchema.ID, | ||
Data: map[string]interface{}{ | ||
"email": "[email protected]", | ||
}, | ||
Expiry: time.Now().Add(24 * time.Hour).Format(time.RFC3339), | ||
Revocable: true, | ||
}) | ||
|
||
assert.NoError(tt, err) | ||
assert.NotEmpty(tt, createdCredTwo) | ||
assert.NotEmpty(tt, createdCredTwo.CredentialJWT) | ||
|
||
credStatusMapTwo, ok := createdCredTwo.Credential.CredentialStatus.(map[string]interface{}) | ||
assert.True(tt, ok) | ||
|
||
assert.Contains(tt, credStatusMapTwo["id"], fmt.Sprintf("v1/credentials/%s/status", createdCredTwo.ID)) | ||
assert.Contains(tt, credStatusMapTwo["statusListCredential"], "v1/credentials/status") | ||
assert.NotEmpty(tt, credStatusMapTwo["statusListIndex"]) | ||
|
||
}) | ||
} |
Oops, something went wrong.