Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2602 from soluchok/bbs_bdd_controller_test
Browse files Browse the repository at this point in the history
feat: BBS+ BDD tests for PE
  • Loading branch information
fqutishat authored Mar 4, 2021
2 parents 16ffd16 + d33f83b commit f56b2ce
Show file tree
Hide file tree
Showing 7 changed files with 404 additions and 29 deletions.
21 changes: 14 additions & 7 deletions pkg/controller/command/verifiable/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,21 @@ type kmsSigner struct {
bbs bool
}

func newKMSSigner(keyManager kms.KeyManager, c ariescrypto.Crypto, creator string) (*kmsSigner, error) {
// creator will contain didID#keyID
idSplit := strings.Split(creator, "#")
if len(idSplit) != creatorParts {
return nil, fmt.Errorf("wrong id %s to resolve", idSplit)
func getKID(opts *ProofOptions) string {
if opts.KID != "" {
return opts.KID
}

keyHandler, err := keyManager.Get(idSplit[1])
idSplit := strings.Split(opts.VerificationMethod, "#")
if len(idSplit) == creatorParts {
return idSplit[1]
}

return ""
}

func newKMSSigner(keyManager kms.KeyManager, c ariescrypto.Crypto, kid string) (*kmsSigner, error) {
keyHandler, err := keyManager.Get(kid)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -847,7 +854,7 @@ func (o *Command) createAndSignPresentationByID(vc *verifiable.Credential,
}

func (o *Command) addLinkedDataProof(p provable, opts *ProofOptions) error {
s, err := newKMSSigner(o.ctx.KMS(), o.ctx.Crypto(), opts.VerificationMethod)
s, err := newKMSSigner(o.ctx.KMS(), o.ctx.Crypto(), getKID(opts))
if err != nil {
return err
}
Expand Down
14 changes: 0 additions & 14 deletions pkg/controller/command/verifiable/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1300,20 +1300,6 @@ func TestGeneratePresentationHelperFunctions(t *testing.T) {
require.NotNil(t, cmd)
require.NoError(t, cmdErr)

t.Run("test generate presentation helper- error", func(t *testing.T) {
v := &verifiable.Credential{}
err := json.Unmarshal([]byte(vc), v)
require.NoError(t, err)

credList := make([]*verifiable.Credential, 1)
credList[0] = v

var b bytes.Buffer
err = cmd.generatePresentation(&b, credList, nil, "did:example", &ProofOptions{VerificationMethod: "pk"})
require.Error(t, err)
require.Contains(t, err.Error(), "prepare vp: failed to sign vp: wrong id [pk] to resolve")
})

t.Run("test generate presentation by id helper- error", func(t *testing.T) {
cred := &verifiable.Credential{}
err := json.Unmarshal([]byte(vc), cred)
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/command/verifiable/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type IDArg struct {

// ProofOptions is model to allow the dynamic proofing options by the user.
type ProofOptions struct {
KID string `json:"kid,omitempty"`
// VerificationMethod is the URI of the verificationMethod used for the proof.
VerificationMethod string `json:"verificationMethod,omitempty"`
SignatureRepresentation *docverifiable.SignatureRepresentation `json:"signatureRepresentation,omitempty"`
Expand Down
12 changes: 12 additions & 0 deletions test/bdd/features/presentproof_controller.feature
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ Feature: Present Proof using controller API
Then "Alice" successfully accepts a presentation with "passport" name through PresentProof controller
And "Alice" checks that presentation is being stored under the "passport" name

@present_proof_controller_bbs
Scenario: The Verifier begins with a presentation request (BBS+)
Given "Jennifer" agent is running on "localhost" port "8081" with controller "https://localhost:8082"
And "Julia" agent is running on "localhost" port "9081" with controller "https://localhost:9082"
And "Jennifer" has established connection with "Julia" through PresentProof controller

When "Jennifer" sends a request presentation with presentation definition to "Julia" through PresentProof controller
And "Julia" accepts a request and sends credentials with BBS to the Verifier through PresentProof controller

Then "Jennifer" successfully accepts a presentation with "bbs-passport" name through PresentProof controller
And "Jennifer" checks that presentation is being stored under the "bbs-passport" name

Scenario: The Prover begins with a presentation proposal
Given "Carol" agent is running on "localhost" port "8081" with controller "https://localhost:8082"
And "Dan" agent is running on "localhost" port "9081" with controller "https://localhost:9082"
Expand Down
15 changes: 15 additions & 0 deletions test/bdd/fixtures/agent-rest/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ services:
networks:
- bdd_net

static-file-server:
container_name: static-file-server
image: halverneus/static-file-server:latest
environment:
- PORT=8089
- FOLDER=/web
- CORS=true
- VIRTUAL_PORT=8089
ports:
- 8089:8089
volumes:
- ./schema:/web
networks:
- bdd_net

erin.agent.example.com:
container_name: erin.aries.example.com
image: ${AGENT_REST_IMAGE}:${AGENT_REST_IMAGE_TAG}
Expand Down
193 changes: 193 additions & 0 deletions test/bdd/fixtures/agent-rest/schema/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
{
"required": [
"@context",
"type",
"credentialSubject",
"issuer",
"issuanceDate"
],
"properties": {
"@context": {
"oneOf": [
{
"type": "string",
"const": "https://www.w3.org/2018/credentials/v1"
},
{
"type": "array",
"items": [
{
"type": "string",
"const": "https://www.w3.org/2018/credentials/v1"
}
],
"uniqueItems": true,
"additionalItems": {
"oneOf": [
{
"type": "object"
},
{
"type": "string"
}
]
}
}
]
},
"id": {
"type": "string",
"format": "uri"
},
"type": {
"oneOf": [
{
"type": "array",
"minItems": 1,
"contains": {
"type": "string",
"pattern": "^VerifiableCredential$"
}
},
{
"type": "string",
"pattern": "^VerifiableCredential$"
}
]
},
"credentialSubject": {
"anyOf": [
{
"type": "array"
},
{
"type": "object"
},
{
"type": "string"
}
]
},
"issuer": {
"anyOf": [
{
"type": "string",
"format": "uri"
},
{
"type": "object",
"required": [
"id"
],
"properties": {
"id": {
"type": "string",
"format": "uri"
}
}
}
]
},
"issuanceDate": {
"type": "string",
"format": "date-time"
},
"proof": {
"anyOf": [
{
"$ref": "#/definitions/proof"
},
{
"type": "array",
"items": {
"$ref": "#/definitions/proof"
}
},
{
"type": "null"
}
]
},
"expirationDate": {
"type": [
"string",
"null"
],
"format": "date-time"
},
"credentialStatus": {
"$ref": "#/definitions/typedID"
},
"credentialSchema": {
"$ref": "#/definitions/typedIDs"
},
"evidence": {
"$ref": "#/definitions/typedIDs"
},
"refreshService": {
"$ref": "#/definitions/typedID"
}
},
"definitions": {
"typedID": {
"anyOf": [
{
"type": "null"
},
{
"type": "object",
"required": [
"id",
"type"
],
"properties": {
"id": {
"type": "string",
"format": "uri"
},
"type": {
"anyOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
}
}
}
]
},
"typedIDs": {
"anyOf": [
{
"$ref": "#/definitions/typedID"
},
{
"type": "array",
"items": {
"$ref": "#/definitions/typedID"
}
},
{
"type": "null"
}
]
},
"proof": {
"type": "object",
"required": [
"type"
],
"properties": {
"type": {
"type": "string"
}
}
}
}
}
Loading

0 comments on commit f56b2ce

Please sign in to comment.