Skip to content

Commit

Permalink
Supporting SQL based storage
Browse files Browse the repository at this point in the history
  • Loading branch information
andresuribe87 committed Jul 12, 2023
1 parent 3fcae9b commit afdcff0
Show file tree
Hide file tree
Showing 21 changed files with 648 additions and 122 deletions.
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/benbjohnson/clock v1.3.5
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.2
github.com/cenkalti/backoff/v4 v4.2.1
github.com/fergusstrange/embedded-postgres v1.23.0
github.com/gin-contrib/cors v1.4.0
github.com/gin-gonic/gin v1.9.1
github.com/go-playground/locales v0.14.1
Expand Down Expand Up @@ -117,6 +118,7 @@ require (
github.com/lestrrat-go/httprc v1.0.4 // indirect
github.com/lestrrat-go/iter v1.0.2 // indirect
github.com/lestrrat-go/option v1.0.1 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
Expand Down Expand Up @@ -155,6 +157,7 @@ require (
github.com/swaggo/swag v1.16.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
github.com/yuin/gopher-lua v1.1.0 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/otel/metric v1.16.0 // indirect
Expand Down
9 changes: 7 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbi
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
github.com/TBD54566975/ssi-sdk v0.0.4-alpha.0.20230707203029-1bbf9c13be59 h1:O7GtPvUMsbJYFGx+In7ai1Sxm7gQaF7fenwlovpYbvs=
github.com/TBD54566975/ssi-sdk v0.0.4-alpha.0.20230707203029-1bbf9c13be59/go.mod h1:yPkVO9MCC/kRu+lut3jllhnCV0gEqSubaaSVT7xLSOs=
github.com/TBD54566975/ssi-sdk v0.0.4-alpha.0.20230711190054-bce640c9bf25 h1:wW+49kQxN/BYcMkbDjQA9mkrUC9cYUV6HOFLP+JIx+E=
github.com/TBD54566975/ssi-sdk v0.0.4-alpha.0.20230711190054-bce640c9bf25/go.mod h1:lup1EqGAT730/c7dRF9Q8OvgsjWJewq4K2dFAyBV1vk=
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc=
Expand Down Expand Up @@ -138,6 +136,8 @@ github.com/fatih/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4
github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94=
github.com/felixge/httpsnoop v1.0.3 h1:s/nj+GCswXYzN5v2DpNMuMQYe+0DDwt5WVCU6CWBdXk=
github.com/felixge/httpsnoop v1.0.3/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/fergusstrange/embedded-postgres v1.23.0 h1:ZYRD89nammxQDWDi6taJE2CYjDuAoVc1TpEqRIYQryc=
github.com/fergusstrange/embedded-postgres v1.23.0/go.mod h1:wL562t1V+iuFwq0UcgMi2e9rp8CROY9wxWZEfP8Y874=
github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
Expand Down Expand Up @@ -351,6 +351,8 @@ github.com/lestrrat-go/jwx/v2 v2.0.11/go.mod h1:ZtPtMFlrfDrH2Y0iwfa3dRFn8VzwBrB+
github.com/lestrrat-go/option v1.0.0/go.mod h1:5ZHFbivi4xwXxhxY9XHDe2FHo6/Z7WWmtT7T5nBBp3I=
github.com/lestrrat-go/option v1.0.1 h1:oAzP2fvZGQKWkvHa1/SAcFolBEca1oN+mQ7eooNBEYU=
github.com/lestrrat-go/option v1.0.1/go.mod h1:5ZHFbivi4xwXxhxY9XHDe2FHo6/Z7WWmtT7T5nBBp3I=
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/magefile/mage v1.15.0 h1:BvGheCMAsG3bWUDbZ8AyXXpCNwU9u5CB6sM+HNb9HYg=
github.com/magefile/mage v1.15.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
Expand Down Expand Up @@ -488,6 +490,8 @@ github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6
github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 h1:nIPpBwaJSVYIxUFsDv3M8ofmx9yWTog9BfvIu0q41lo=
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMxjDjgmT5uz5wzYJKVo23qUhYTos=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down Expand Up @@ -524,6 +528,7 @@ go.opentelemetry.io/otel/sdk v1.16.0/go.mod h1:tMsIuKXuuIWPBAOrH+eHtvhTL+SntFtXF
go.opentelemetry.io/otel/trace v1.16.0 h1:8JRpaObFoW0pxuVPapkgH8UhHQj+bJW8jJsCZEu5MQs=
go.opentelemetry.io/otel/trace v1.16.0/go.mod h1:Yt9vYq1SdNz3xdjZZK7wcXv1qv2pwLkqr2QVwea0ef0=
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k=
golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
Expand Down
32 changes: 16 additions & 16 deletions pkg/server/router/credential_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestCredentialRouter(t *testing.T) {
})

t.Run("Credential Service Test", func(tt *testing.T) {
s := test.ServiceStorage(t)
s := test.ServiceStorage(tt)
assert.NotEmpty(tt, s)

serviceConfig := config.CredentialServiceConfig{BaseServiceConfig: &config.BaseServiceConfig{Name: "credential"}}
Expand Down Expand Up @@ -201,7 +201,7 @@ func TestCredentialRouter(t *testing.T) {
})

t.Run("Credential Service Test Revoked Key", func(tt *testing.T) {
s := test.ServiceStorage(t)
s := test.ServiceStorage(tt)
assert.NotEmpty(tt, s)

// Initialize services
Expand Down Expand Up @@ -264,7 +264,7 @@ func TestCredentialRouter(t *testing.T) {
})

t.Run("Credential Status List Test", func(tt *testing.T) {
s := test.ServiceStorage(t)
s := test.ServiceStorage(tt)
assert.NotEmpty(tt, s)

serviceConfig := config.CredentialServiceConfig{BaseServiceConfig: &config.BaseServiceConfig{Name: "credential", ServiceEndpoint: "v1/credentials"}}
Expand Down Expand Up @@ -373,7 +373,7 @@ func TestCredentialRouter(t *testing.T) {
})

t.Run("Credential Status List Test No Schemas", func(tt *testing.T) {
s := test.ServiceStorage(t)
s := test.ServiceStorage(tt)
assert.NotEmpty(tt, s)

serviceConfig := config.CredentialServiceConfig{BaseServiceConfig: &config.BaseServiceConfig{Name: "credential", ServiceEndpoint: "/v1/credentials"}}
Expand Down Expand Up @@ -477,7 +477,7 @@ func TestCredentialRouter(t *testing.T) {
})

t.Run("Credential Status List Test Update Revoked Status", func(tt *testing.T) {
s := test.ServiceStorage(t)
s := test.ServiceStorage(tt)
assert.NotEmpty(tt, s)

serviceConfig := config.CredentialServiceConfig{BaseServiceConfig: &config.BaseServiceConfig{Name: "credential", ServiceEndpoint: "http://localhost:1234/v1/credentials"}}
Expand Down Expand Up @@ -597,7 +597,7 @@ func TestCredentialRouter(t *testing.T) {
})

t.Run("Credential Status List Test Update Suspended Status", func(tt *testing.T) {
s := test.ServiceStorage(t)
s := test.ServiceStorage(tt)
assert.NotEmpty(tt, s)

serviceConfig := config.CredentialServiceConfig{BaseServiceConfig: &config.BaseServiceConfig{Name: "credential", ServiceEndpoint: "http://localhost:1234/v1/credentials"}}
Expand Down Expand Up @@ -717,7 +717,7 @@ func TestCredentialRouter(t *testing.T) {
})

t.Run("Create Multiple Suspendable Credential Different IssuerDID SchemaID StatusPurpose Triples", func(tt *testing.T) {
s := test.ServiceStorage(t)
s := test.ServiceStorage(tt)
assert.NotEmpty(tt, s)

serviceConfig := config.CredentialServiceConfig{BaseServiceConfig: &config.BaseServiceConfig{Name: "credential", ServiceEndpoint: "http://localhost:1234/v1/credentials"}}
Expand Down Expand Up @@ -801,7 +801,7 @@ func TestCredentialRouter(t *testing.T) {
})

t.Run("Create Suspendable Credential", func(tt *testing.T) {
issuer, verificationMethodID, schemaID, credService := createCredServicePrereqs(tt, test.ServiceStorage(t))
issuer, verificationMethodID, schemaID, credService := createCredServicePrereqs(tt, test.ServiceStorage(tt))
subject := "did:test:345"

createdCred, err := credService.CreateCredential(context.Background(), credential.CreateCredentialRequest{
Expand Down Expand Up @@ -857,7 +857,7 @@ func TestCredentialRouter(t *testing.T) {
})

t.Run("Update Suspendable Credential To Suspended", func(tt *testing.T) {
issuer, verificationMethodID, schemaID, credService := createCredServicePrereqs(tt, test.ServiceStorage(t))
issuer, verificationMethodID, schemaID, credService := createCredServicePrereqs(tt, test.ServiceStorage(tt))
subject := "did:test:345"

createdCred, err := credService.CreateCredential(context.Background(), credential.CreateCredentialRequest{
Expand Down Expand Up @@ -935,7 +935,7 @@ func TestCredentialRouter(t *testing.T) {
})

t.Run("Update Suspendable Credential To Suspended then Unsuspended", func(tt *testing.T) {
issuer, verificationMethodID, schemaID, credService := createCredServicePrereqs(tt, test.ServiceStorage(t))
issuer, verificationMethodID, schemaID, credService := createCredServicePrereqs(tt, test.ServiceStorage(tt))
subject := "did:test:345"

createdCred, err := credService.CreateCredential(context.Background(), credential.CreateCredentialRequest{
Expand Down Expand Up @@ -1018,7 +1018,7 @@ func TestCredentialRouter(t *testing.T) {
})

t.Run("Create Suspendable and Revocable Credential Should Be Error", func(tt *testing.T) {
issuer, verificationMethodID, schemaID, credService := createCredServicePrereqs(tt, test.ServiceStorage(t))
issuer, verificationMethodID, schemaID, credService := createCredServicePrereqs(tt, test.ServiceStorage(tt))
subject := "did:test:345"

createdCred, err := credService.CreateCredential(context.Background(), credential.CreateCredentialRequest{
Expand All @@ -1040,7 +1040,7 @@ func TestCredentialRouter(t *testing.T) {
})

t.Run("Update Suspendable and Revocable Credential Should Be Error", func(tt *testing.T) {
issuer, verificationMethodID, schemaID, credService := createCredServicePrereqs(tt, test.ServiceStorage(t))
issuer, verificationMethodID, schemaID, credService := createCredServicePrereqs(tt, test.ServiceStorage(tt))
subject := "did:test:345"

createdCred, err := credService.CreateCredential(context.Background(), credential.CreateCredentialRequest{
Expand All @@ -1065,7 +1065,7 @@ func TestCredentialRouter(t *testing.T) {
})

t.Run("Update Suspended On Revoked Credential Should Be Error", func(tt *testing.T) {
issuer, verificationMethodID, schemaID, credService := createCredServicePrereqs(tt, test.ServiceStorage(t))
issuer, verificationMethodID, schemaID, credService := createCredServicePrereqs(tt, test.ServiceStorage(tt))
subject := "did:test:345"

createdCred, err := credService.CreateCredential(context.Background(), credential.CreateCredentialRequest{
Expand All @@ -1090,7 +1090,7 @@ func TestCredentialRouter(t *testing.T) {
})

t.Run("Create Credential With Invalid Evidence", func(tt *testing.T) {
issuer, verificationMethodID, schemaID, credService := createCredServicePrereqs(tt, test.ServiceStorage(t))
issuer, verificationMethodID, schemaID, credService := createCredServicePrereqs(tt, test.ServiceStorage(tt))
subject := "did:test:345"

_, err := credService.CreateCredential(context.Background(), credential.CreateCredentialRequest{
Expand All @@ -1109,7 +1109,7 @@ func TestCredentialRouter(t *testing.T) {
})

t.Run("Create Credential With Invalid Evidence No Id", func(tt *testing.T) {
issuer, verificationMethodID, schemaID, credService := createCredServicePrereqs(tt, test.ServiceStorage(t))
issuer, verificationMethodID, schemaID, credService := createCredServicePrereqs(tt, test.ServiceStorage(tt))
subject := "did:test:345"

evidenceMap := map[string]any{
Expand Down Expand Up @@ -1137,7 +1137,7 @@ func TestCredentialRouter(t *testing.T) {
})

t.Run("Create Credential With Evidence", func(tt *testing.T) {
issuer, verificationMethodID, schemaID, credService := createCredServicePrereqs(tt, test.ServiceStorage(t))
issuer, verificationMethodID, schemaID, credService := createCredServicePrereqs(tt, test.ServiceStorage(tt))
subject := "did:test:345"

createdCred, err := credService.CreateCredential(context.Background(), credential.CreateCredentialRequest{
Expand Down
6 changes: 3 additions & 3 deletions pkg/server/router/did_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestDIDRouter(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(t)
db := test.ServiceStorage(tt)
assert.NotEmpty(tt, db)
keyStoreService := testKeyStoreService(tt, db)
methods := []string{didsdk.KeyMethod.String()}
Expand Down Expand Up @@ -77,7 +77,7 @@ func TestDIDRouter(t *testing.T) {
}

t.Run("DID Service Test", func(tt *testing.T) {
db := test.ServiceStorage(t)
db := test.ServiceStorage(tt)
assert.NotEmpty(tt, db)

keyStoreService := testKeyStoreService(tt, db)
Expand Down Expand Up @@ -164,7 +164,7 @@ func TestDIDRouter(t *testing.T) {
})

t.Run("DID Web Service Test", func(tt *testing.T) {
db := test.ServiceStorage(t)
db := test.ServiceStorage(tt)
assert.NotEmpty(tt, db)

keyStoreService := testKeyStoreService(tt, db)
Expand Down
2 changes: 1 addition & 1 deletion pkg/server/router/keystore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestKeyStoreRouter(t *testing.T) {
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(t)
db := test.ServiceStorage(tt)
assert.NotEmpty(tt, db)

serviceConfig := config.KeyStoreServiceConfig{
Expand Down
6 changes: 3 additions & 3 deletions pkg/server/router/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestManifestRouter(t *testing.T) {
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(t)
db := test.ServiceStorage(tt)
assert.NotEmpty(tt, db)

keyStoreService := testKeyStoreService(tt, db)
Expand Down Expand Up @@ -93,10 +93,10 @@ func TestManifestRouter(t *testing.T) {
createManifestRequest.PresentationDefinitionRef = &model.PresentationDefinitionRef{
ID: &resp.PresentationDefinition.ID,
}
manifest, err := manifestService.CreateManifest(context.Background(), createManifestRequest)
createdManifest, err := manifestService.CreateManifest(context.Background(), createManifestRequest)

assert.NoError(ttt, err)
assert.Equal(ttt, resp.PresentationDefinition, *manifest.Manifest.PresentationDefinition)
assert.Equal(ttt, resp.PresentationDefinition, *createdManifest.Manifest.PresentationDefinition)
})

tt.Run("multiple behaviors", func(ttt *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions pkg/server/router/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestSchemaRouter(t *testing.T) {
t.Run(test.Name, func(t *testing.T) {

t.Run("Schema Service Test", func(tt *testing.T) {
db := test.ServiceStorage(t)
db := test.ServiceStorage(tt)
assert.NotEmpty(tt, db)

serviceConfig := config.SchemaServiceConfig{BaseServiceConfig: &config.BaseServiceConfig{Name: "schema"}}
Expand Down Expand Up @@ -117,7 +117,7 @@ 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(t)
db := test.ServiceStorage(tt)
assert.NotEmpty(tt, db)

serviceConfig := config.SchemaServiceConfig{BaseServiceConfig: &config.BaseServiceConfig{Name: "schema"}}
Expand All @@ -142,7 +142,7 @@ func TestSchemaSigning(t *testing.T) {
})

t.Run("Signing schema with revoked key test", func(tt *testing.T) {
db := test.ServiceStorage(t)
db := test.ServiceStorage(tt)
assert.NotEmpty(tt, db)

serviceConfig := config.SchemaServiceConfig{BaseServiceConfig: &config.BaseServiceConfig{Name: "schema"}}
Expand Down
2 changes: 1 addition & 1 deletion pkg/server/router/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestWebhookRouter(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(t)
db := test.ServiceStorage(tt)
require.NotEmpty(tt, db)

serviceConfig := config.WebhookServiceConfig{WebhookTimeout: "10s"}
Expand Down
Loading

0 comments on commit afdcff0

Please sign in to comment.