Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
infohub
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gaia-X
Trust Services API
infohub
Merge requests
!4
Unit tests for infohub export functionality
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Unit tests for infohub export functionality
8-export-unit-tests
into
main
Overview
2
Commits
1
Pipelines
1
Changes
11
Merged
Lyuben Penkovski
requested to merge
8-export-unit-tests
into
main
2 years ago
Overview
2
Commits
1
Pipelines
1
Changes
11
Expand
Closes
#8 (closed)
@yordan.kinkov
@valerii.kalashnikov
0
0
Merge request reports
Compare
main
main (base)
and
latest version
latest version
df826b19
1 commit,
2 years ago
11 files
+
1125
−
183
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
11
Search (e.g. *.vue) (Ctrl+P)
internal/clients/signer/client_test.go
0 → 100644
+
131
−
0
Options
package
signer_test
import
(
"context"
"net/http"
"net/http/httptest"
"testing"
"github.com/hyperledger/aries-framework-go/pkg/doc/verifiable"
"github.com/piprate/json-gold/ld"
"github.com/stretchr/testify/assert"
"code.vereign.com/gaiax/tsa/infohub/internal/clients/signer"
)
const
invalidPresentation
=
`{"invalid":"verifiable_presentation"}`
const
validPresentation
=
`{
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://www.w3.org/2018/credentials/examples/v1"
],
"id": "did:123",
"type": "VerifiablePresentation",
"verifiableCredential": [
{
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://www.w3.org/2018/credentials/examples/v1"
],
"credentialSubject": {
"allow": true,
"id": "example/example/1.0",
"taskID": "0123456789abcdef"
},
"issuanceDate": "2022-06-14T08:43:22.78309334Z",
"issuer": "https://example.com",
"type": "VerifiableCredential"
},
{
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://www.w3.org/2018/credentials/examples/v1"
],
"credentialSubject": {
"id": "example/example/2.0",
"result": {
"hello": "world"
}
},
"issuanceDate": "2022-06-14T08:43:22.783102173Z",
"issuer": "https://example.com",
"type": "VerifiableCredential"
}
]
}`
func
TestClient_PresentationProof
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
ctx
context
.
Context
vp
*
verifiable
.
Presentation
handler
http
.
HandlerFunc
result
*
verifiable
.
Presentation
errtext
string
}{
{
name
:
"error creating http request because of nil context"
,
errtext
:
"net/http: nil Context"
,
},
{
name
:
"signer server returns unexpected response code"
,
ctx
:
context
.
Background
(),
handler
:
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
w
.
WriteHeader
(
http
.
StatusServiceUnavailable
)
},
errtext
:
"unexpected response from signer: 503 Service Unavailable"
,
},
{
name
:
"signer server returns empty response"
,
ctx
:
context
.
Background
(),
handler
:
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
w
.
WriteHeader
(
http
.
StatusOK
)
},
errtext
:
"JSON unmarshalling of verifiable presentation: unexpected end of JSON input"
,
},
{
name
:
"signer server returns invalid verifiable presentation"
,
ctx
:
context
.
Background
(),
handler
:
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
w
.
WriteHeader
(
http
.
StatusOK
)
_
,
_
=
w
.
Write
([]
byte
(
invalidPresentation
))
},
errtext
:
"verifiable presentation is not valid"
,
},
{
name
:
"signer server returns valid presentation"
,
ctx
:
context
.
Background
(),
handler
:
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
w
.
WriteHeader
(
http
.
StatusOK
)
_
,
_
=
w
.
Write
([]
byte
(
validPresentation
))
},
},
}
for
_
,
test
:=
range
tests
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
signerSrv
:=
httptest
.
NewServer
(
test
.
handler
)
client
:=
signer
.
New
(
signerSrv
.
URL
,
signer
.
WithHTTPClient
(
http
.
DefaultClient
))
result
,
err
:=
client
.
PresentationProof
(
test
.
ctx
,
test
.
vp
)
if
err
!=
nil
{
assert
.
Nil
(
t
,
result
)
assert
.
NotEmpty
(
t
,
test
.
errtext
)
assert
.
Contains
(
t
,
err
.
Error
(),
test
.
errtext
)
}
else
{
assert
.
Empty
(
t
,
test
.
errtext
)
assert
.
NotNil
(
t
,
result
)
// parse the string representation to compare with the returned result
vp
,
err
:=
verifiable
.
ParsePresentation
(
[]
byte
(
validPresentation
),
verifiable
.
WithPresJSONLDDocumentLoader
(
ld
.
NewDefaultDocumentLoader
(
http
.
DefaultClient
)),
verifiable
.
WithPresDisabledProofCheck
(),
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
vp
,
result
)
}
})
}
}
Loading