Skip to content

Commit

Permalink
fix: test to use t *testing.T instead of tt *testing.T (#717)
Browse files Browse the repository at this point in the history
  • Loading branch information
atsushii authored Dec 5, 2023
1 parent 2757541 commit 8f87d43
Show file tree
Hide file tree
Showing 21 changed files with 2,506 additions and 2,504 deletions.
82 changes: 41 additions & 41 deletions internal/keyaccess/dataintegrity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 8f87d43

Please sign in to comment.