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 53
Fixing Cred Suspension Bug #487
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4539945
fixing bug
nitro-neal 781c0b2
Merge branch 'main' into fix-suspension-bug
nitro-neal b5d189c
updates
nitro-neal 77182e0
Merge branch 'main' into fix-suspension-bug
nitro-neal e9f8ae0
small fixes
nitro-neal f7a3122
Merge branch 'main' into fix-suspension-bug
nitro-neal 3eaeaaf
updated to use json template
nitro-neal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,234 @@ | ||
package integration | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/TBD54566975/ssi-sdk/credential" | ||
"github.com/TBD54566975/ssi-sdk/credential/status" | ||
"github.com/goccy/go-json" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var credentialSuspensionContext = NewTestContext("CredentialSuspension") | ||
|
||
func TestSuspensionCreateIssuerDIDKeyIntegration(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip("skipping integration test") | ||
} | ||
|
||
didKeyOutput, err := CreateDIDKey() | ||
assert.NoError(t, err) | ||
|
||
issuerDID, err := getJSONElement(didKeyOutput, "$.did.id") | ||
assert.NoError(t, err) | ||
assert.Contains(t, issuerDID, "did:key") | ||
SetValue(credentialSuspensionContext, "issuerDID", issuerDID) | ||
|
||
issuerKID, err := getJSONElement(didKeyOutput, "$.did.verificationMethod[0].id") | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, issuerKID) | ||
SetValue(credentialSuspensionContext, "issuerKID", issuerKID) | ||
} | ||
|
||
func TestSuspensionCreateSchemaIntegration(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip("skipping integration test") | ||
} | ||
|
||
output, err := CreateKYCSchema() | ||
assert.NoError(t, err) | ||
|
||
schemaID, err := getJSONElement(output, "$.id") | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, schemaID) | ||
SetValue(credentialSuspensionContext, "schemaID", schemaID) | ||
} | ||
|
||
func TestSuspensionCreateVerifiableCredentialIntegration(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip("skipping integration test") | ||
} | ||
|
||
issuerDID, err := GetValue(credentialSuspensionContext, "issuerDID") | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, issuerDID) | ||
|
||
issuerKID, err := GetValue(credentialSuspensionContext, "issuerKID") | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, issuerKID) | ||
|
||
schemaID, err := GetValue(credentialSuspensionContext, "schemaID") | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, schemaID) | ||
|
||
vcOutput, err := CreateVerifiableCredential(credInputParams{ | ||
IssuerID: issuerDID.(string), | ||
IssuerKID: issuerKID.(string), | ||
SchemaID: schemaID.(string), | ||
SubjectID: issuerDID.(string), | ||
Suspendable: true, | ||
}) | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, vcOutput) | ||
|
||
cred, err := getJSONElement(vcOutput, "$.credential") | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, cred) | ||
SetValue(credentialSuspensionContext, "cred", cred) | ||
|
||
credStatusURL, err := getJSONElement(vcOutput, "$.credential.credentialStatus.id") | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, credStatusURL) | ||
assert.Contains(t, credStatusURL, "http") | ||
SetValue(credentialSuspensionContext, "credStatusURL", credStatusURL) | ||
|
||
fmt.Print(credStatusURL) | ||
|
||
statusListCredentialURL, err := getJSONElement(vcOutput, "$.credential.credentialStatus.statusListCredential") | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, statusListCredentialURL) | ||
assert.Contains(t, statusListCredentialURL, "http") | ||
SetValue(credentialSuspensionContext, "statusListCredentialURL", statusListCredentialURL) | ||
|
||
credStatusListCredentialOutput, err := get(statusListCredentialURL) | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, credStatusListCredentialOutput) | ||
|
||
encodedListOriginal, err := getJSONElement(credStatusListCredentialOutput, "$.credential.credentialSubject.encodedList") | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, encodedListOriginal) | ||
SetValue(credentialSuspensionContext, "encodedListOriginal", encodedListOriginal) | ||
} | ||
|
||
func TestSuspensionCheckStatusIntegration(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip("skipping integration test") | ||
} | ||
|
||
credStatusURL, err := GetValue(credentialSuspensionContext, "credStatusURL") | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, credStatusURL) | ||
|
||
credStatusOutput, err := get(credStatusURL.(string)) | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, credStatusOutput) | ||
|
||
suspended, err := getJSONElement(credStatusOutput, "$.suspended") | ||
assert.NoError(t, err) | ||
assert.Equal(t, "false", suspended) | ||
|
||
suspendedOutput, err := put(credStatusURL.(string), getJSONFromFile("suspended-input.json")) | ||
assert.NoError(t, err) | ||
|
||
suspended, err = getJSONElement(suspendedOutput, "$.suspended") | ||
assert.NoError(t, err) | ||
assert.Equal(t, "true", suspended) | ||
|
||
credStatusOutput, err = get(credStatusURL.(string)) | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, credStatusOutput) | ||
|
||
suspended, err = getJSONElement(credStatusOutput, "$.suspended") | ||
assert.NoError(t, err) | ||
assert.Equal(t, "true", suspended) | ||
} | ||
|
||
func TestSuspensionCheckStatusListCredentialIntegration(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip("skipping integration test") | ||
} | ||
|
||
statusListCredentialURL, err := GetValue(credentialSuspensionContext, "statusListCredentialURL") | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, statusListCredentialURL) | ||
|
||
credStatusListCredentialOutput, err := get(statusListCredentialURL.(string)) | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, credStatusListCredentialOutput) | ||
|
||
statusListType, err := getJSONElement(credStatusListCredentialOutput, "$.credential.credentialSubject.type") | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, statusListType) | ||
assert.Equal(t, "StatusList2021", statusListType) | ||
|
||
encodedList, err := getJSONElement(credStatusListCredentialOutput, "$.credential.credentialSubject.encodedList") | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, encodedList) | ||
|
||
encodedListOriginal, err := GetValue(credentialSuspensionContext, "encodedListOriginal") | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, encodedListOriginal) | ||
|
||
assert.NotEqual(t, encodedListOriginal.(string), encodedList) | ||
} | ||
|
||
func TestSuspensionValidateCredentialInStatusListIntegration(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip("skipping integration test") | ||
} | ||
|
||
credJSON, err := GetValue(credentialSuspensionContext, "cred") | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, credJSON) | ||
|
||
var vc credential.VerifiableCredential | ||
err = json.Unmarshal([]byte(credJSON.(string)), &vc) | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, vc) | ||
|
||
statusListCredentialURL, err := GetValue(credentialSuspensionContext, "statusListCredentialURL") | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, statusListCredentialURL) | ||
|
||
credStatusListCredentialOutput, err := get(statusListCredentialURL.(string)) | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, credStatusListCredentialOutput) | ||
|
||
credStatusListCredentialJSON, err := getJSONElement(credStatusListCredentialOutput, "$.credential") | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, credStatusListCredentialJSON) | ||
|
||
var vcStatusList credential.VerifiableCredential | ||
err = json.Unmarshal([]byte(credStatusListCredentialJSON), &vcStatusList) | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, vcStatusList) | ||
|
||
// Validate the StatusListIndex in flipped in the credStatusList | ||
valid, err := status.ValidateCredentialInStatusList(vc, vcStatusList) | ||
assert.NoError(t, err) | ||
assert.True(t, valid) | ||
} | ||
|
||
func TestSuspensionUnSuspendCredential(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip("skipping integration test") | ||
} | ||
|
||
credStatusURL, err := GetValue(credentialSuspensionContext, "credStatusURL") | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, credStatusURL) | ||
|
||
credStatusOutput, err := get(credStatusURL.(string)) | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, credStatusOutput) | ||
|
||
suspended, err := getJSONElement(credStatusOutput, "$.suspended") | ||
assert.NoError(t, err) | ||
assert.Equal(t, "true", suspended) | ||
|
||
suspendedOutput, err := put(credStatusURL.(string), `{"suspended":false}`) | ||
assert.NoError(t, err) | ||
|
||
suspended, err = getJSONElement(suspendedOutput, "$.suspended") | ||
assert.NoError(t, err) | ||
assert.Equal(t, "false", suspended) | ||
|
||
credStatusOutput, err = get(credStatusURL.(string)) | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, credStatusOutput) | ||
|
||
suspended, err = getJSONElement(credStatusOutput, "$.suspended") | ||
assert.NoError(t, err) | ||
assert.Equal(t, "false", suspended) | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could this be combined into a
credential_status_integration_test
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it could be, but I opted for a fresh flow, fresh creds, making sure suspension works, didnt want like a revokable cred flow to 'init' something so a suspension would work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm worried about scaling this once we move to a generic status - and not needing to support specific statuses. But fine to save that until we impl that change.