Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
golib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
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
golib
Commits
50e055f2
Commit
50e055f2
authored
2 years ago
by
Yordan Kinkov
Browse files
Options
Downloads
Patches
Plain Diff
Add raw invitation request and result functions to OCM client
parent
9109f705
No related branches found
No related tags found
No related merge requests found
Pipeline
#60067
failed
2 years ago
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitlab-ci.yml
+2
-2
2 additions, 2 deletions
.gitlab-ci.yml
ocm/client.go
+68
-10
68 additions, 10 deletions
ocm/client.go
ocm/client_test.go
+118
-0
118 additions, 0 deletions
ocm/client_test.go
with
188 additions
and
12 deletions
.gitlab-ci.yml
+
2
−
2
View file @
50e055f2
...
@@ -6,7 +6,7 @@ before_script:
...
@@ -6,7 +6,7 @@ before_script:
-
cd /go/src/gitlab.com/${CI_PROJECT_PATH}
-
cd /go/src/gitlab.com/${CI_PROJECT_PATH}
unit tests
:
unit tests
:
image
:
golang:1.
19.4
image
:
golang:1.
20.2
stage
:
test
stage
:
test
tags
:
tags
:
-
amd64-docker
-
amd64-docker
...
@@ -28,7 +28,7 @@ lint:
...
@@ -28,7 +28,7 @@ lint:
-
golangci-lint run
-
golangci-lint run
govulncheck
:
govulncheck
:
image
:
golang:1.
19.4
image
:
golang:1.
20.2
stage
:
test
stage
:
test
tags
:
tags
:
-
amd64-docker
-
amd64-docker
...
...
This diff is collapsed.
Click to expand it.
ocm/client.go
+
68
−
10
View file @
50e055f2
package
ocm
package
ocm
import
(
import
(
"bytes"
"context"
"context"
"encoding/json"
"encoding/json"
"fmt"
"fmt"
...
@@ -11,8 +12,9 @@ import (
...
@@ -11,8 +12,9 @@ import (
)
)
const
(
const
(
proofOutOfBandPath
=
"/v1/out-of-band-proof"
proofOutOfBandPath
=
"/v1/out-of-band-proof"
proofPresentationPath
=
"/v1/find-by-presentation-id"
proofOutOfBandRequestPath
=
"/v1/send-out-of-band-presentation-request"
proofPresentationPath
=
"/v1/find-by-presentation-id"
)
)
// Client is the OCM service client
// Client is the OCM service client
...
@@ -70,16 +72,19 @@ func (c *Client) GetLoginProofInvitation(ctx context.Context, credTypes []string
...
@@ -70,16 +72,19 @@ func (c *Client) GetLoginProofInvitation(ctx context.Context, credTypes []string
return
&
response
,
nil
return
&
response
,
nil
}
}
// GetLoginProofResult calls the "find-by-presentation-id" endpoint in the OCM.
// SendOutOfBandRequest calls the "send out of band presentation request" endpoint on
func
(
c
*
Client
)
GetLoginProofResult
(
ctx
context
.
Context
,
presentationID
string
)
(
*
LoginProofResultResponse
,
error
)
{
// the "out-of-band" protocol in the OCM.
req
,
err
:=
http
.
NewRequestWithContext
(
ctx
,
"GET"
,
c
.
proofManagerAddr
+
proofPresentationPath
,
nil
)
func
(
c
*
Client
)
SendOutOfBandRequest
(
ctx
context
.
Context
,
r
map
[
string
]
interface
{})
(
*
LoginProofInvitationResponse
,
error
)
{
body
,
err
:=
json
.
Marshal
(
r
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
v
:=
url
.
Values
{}
req
,
err
:=
http
.
NewRequestWithContext
(
ctx
,
"POST"
,
c
.
proofManagerAddr
+
proofOutOfBandRequestPath
,
bytes
.
NewBuffer
(
body
))
v
.
Add
(
"presentationId"
,
presentationID
)
if
err
!=
nil
{
req
.
URL
.
RawQuery
=
v
.
Encode
()
return
nil
,
err
}
req
.
Header
.
Set
(
"Content-Type"
,
"application/json"
)
resp
,
err
:=
c
.
httpClient
.
Do
(
req
)
resp
,
err
:=
c
.
httpClient
.
Do
(
req
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -87,7 +92,7 @@ func (c *Client) GetLoginProofResult(ctx context.Context, presentationID string)
...
@@ -87,7 +92,7 @@ func (c *Client) GetLoginProofResult(ctx context.Context, presentationID string)
}
}
defer
resp
.
Body
.
Close
()
// nolint:errcheck
defer
resp
.
Body
.
Close
()
// nolint:errcheck
if
resp
.
StatusCode
!=
http
.
StatusOK
{
if
resp
.
StatusCode
!=
http
.
StatusCreated
&&
resp
.
StatusCode
!=
http
.
StatusOK
{
return
nil
,
fmt
.
Errorf
(
"unexpected response code: %s"
,
resp
.
Status
)
return
nil
,
fmt
.
Errorf
(
"unexpected response code: %s"
,
resp
.
Status
)
}
}
...
@@ -96,10 +101,63 @@ func (c *Client) GetLoginProofResult(ctx context.Context, presentationID string)
...
@@ -96,10 +101,63 @@ func (c *Client) GetLoginProofResult(ctx context.Context, presentationID string)
return
nil
,
err
return
nil
,
err
}
}
var
response
LoginProof
Result
Response
var
response
LoginProof
Invitation
Response
if
err
:=
json
.
Unmarshal
(
bytes
,
&
response
);
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
bytes
,
&
response
);
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
return
&
response
,
nil
return
&
response
,
nil
}
}
// GetLoginProofResult calls the "find-by-presentation-id" endpoint in the OCM.
func
(
c
*
Client
)
GetLoginProofResult
(
ctx
context
.
Context
,
presentationID
string
)
(
*
LoginProofResultResponse
,
error
)
{
resBytes
,
err
:=
c
.
findByPresentationID
(
ctx
,
presentationID
)
if
err
!=
nil
{
return
nil
,
err
}
var
response
LoginProofResultResponse
if
err
:=
json
.
Unmarshal
(
resBytes
,
&
response
);
err
!=
nil
{
return
nil
,
err
}
return
&
response
,
nil
}
// GetRawLoginProofResult calls the "find-by-presentation-id" endpoint in the OCM and returns the raw result.
func
(
c
*
Client
)
GetRawLoginProofResult
(
ctx
context
.
Context
,
presentationID
string
)
(
map
[
string
]
interface
{},
error
)
{
resBytes
,
err
:=
c
.
findByPresentationID
(
ctx
,
presentationID
)
if
err
!=
nil
{
return
nil
,
err
}
var
response
map
[
string
]
interface
{}
if
err
:=
json
.
Unmarshal
(
resBytes
,
&
response
);
err
!=
nil
{
return
nil
,
err
}
return
response
,
nil
}
func
(
c
*
Client
)
findByPresentationID
(
ctx
context
.
Context
,
presentationID
string
)
([]
byte
,
error
)
{
req
,
err
:=
http
.
NewRequestWithContext
(
ctx
,
"GET"
,
c
.
proofManagerAddr
+
proofPresentationPath
,
nil
)
if
err
!=
nil
{
return
nil
,
err
}
v
:=
url
.
Values
{}
v
.
Add
(
"presentationId"
,
presentationID
)
req
.
URL
.
RawQuery
=
v
.
Encode
()
resp
,
err
:=
c
.
httpClient
.
Do
(
req
)
if
err
!=
nil
{
return
nil
,
err
}
defer
resp
.
Body
.
Close
()
// nolint:errcheck
if
resp
.
StatusCode
!=
http
.
StatusOK
{
return
nil
,
fmt
.
Errorf
(
"unexpected response code: %s"
,
resp
.
Status
)
}
return
io
.
ReadAll
(
resp
.
Body
)
}
This diff is collapsed.
Click to expand it.
ocm/client_test.go
+
118
−
0
View file @
50e055f2
...
@@ -46,6 +46,76 @@ func Test_GetLoginProofInvitationErr(t *testing.T) {
...
@@ -46,6 +46,76 @@ func Test_GetLoginProofInvitationErr(t *testing.T) {
assert
.
Contains
(
t
,
err
.
Error
(),
"unexpected response code"
)
assert
.
Contains
(
t
,
err
.
Error
(),
"unexpected response code"
)
}
}
func
Test_SendOutOfBandRequestSuccess
(
t
*
testing
.
T
)
{
expected
:=
&
ocm
.
LoginProofInvitationResponse
{
StatusCode
:
200
,
Message
:
"success"
,
Data
:
ocm
.
LoginProofInvitationResponseData
{},
}
ocmServer
:=
httptest
.
NewServer
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
w
.
WriteHeader
(
http
.
StatusOK
)
_
=
json
.
NewEncoder
(
w
)
.
Encode
(
expected
)
}))
client
:=
ocm
.
New
(
ocmServer
.
URL
)
res
,
err
:=
client
.
SendOutOfBandRequest
(
context
.
Background
(),
map
[
string
]
interface
{}{
"attributes"
:
[]
map
[
string
]
string
{
{
"schemaId"
:
"7KuDTpQh3GJ7Gp6kErpWvM:2:principalTestSchema:1.0"
,
"credentialDefinitionId"
:
"7KuDTpQh3GJ7Gp6kErpWvM:3:CL:40329:principalTestCredDefExpir"
,
"attributeName"
:
"prcLastName"
,
"value"
:
""
,
},
{
"schemaId"
:
"7KuDTpQh3GJ7Gp6kErpWvM:2:principalTestSchema:1.0"
,
"credentialDefinitionId"
:
"7KuDTpQh3GJ7Gp6kErpWvM:3:CL:40329:principalTestCredDefExpir"
,
"attributeName"
:
"email"
,
"value"
:
""
,
},
},
"options"
:
map
[
string
]
string
{
"type"
:
"Aries1.0"
,
},
})
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
expected
.
StatusCode
,
res
.
StatusCode
)
assert
.
Equal
(
t
,
expected
.
Message
,
res
.
Message
)
assert
.
Equal
(
t
,
expected
.
Data
,
res
.
Data
)
}
func
Test_SendOutOfBandRequestErr
(
t
*
testing
.
T
)
{
ocmServer
:=
httptest
.
NewServer
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
w
.
WriteHeader
(
http
.
StatusInternalServerError
)
}))
client
:=
ocm
.
New
(
ocmServer
.
URL
)
res
,
err
:=
client
.
SendOutOfBandRequest
(
context
.
Background
(),
map
[
string
]
interface
{}{
"attributes"
:
[]
map
[
string
]
string
{
{
"schemaId"
:
"7KuDTpQh3GJ7Gp6kErpWvM:2:principalTestSchema:1.0"
,
"credentialDefinitionId"
:
"7KuDTpQh3GJ7Gp6kErpWvM:3:CL:40329:principalTestCredDefExpir"
,
"attributeName"
:
"prcLastName"
,
"value"
:
""
,
},
{
"schemaId"
:
"7KuDTpQh3GJ7Gp6kErpWvM:2:principalTestSchema:1.0"
,
"credentialDefinitionId"
:
"7KuDTpQh3GJ7Gp6kErpWvM:3:CL:40329:principalTestCredDefExpir"
,
"attributeName"
:
"email"
,
"value"
:
""
,
},
},
"options"
:
map
[
string
]
string
{
"type"
:
"Aries1.0"
,
},
})
assert
.
Nil
(
t
,
res
)
assert
.
Error
(
t
,
err
)
assert
.
Contains
(
t
,
err
.
Error
(),
"unexpected response code"
)
}
func
TestClient_GetLoginProofResultSuccess
(
t
*
testing
.
T
)
{
func
TestClient_GetLoginProofResultSuccess
(
t
*
testing
.
T
)
{
expected
:=
&
ocm
.
LoginProofResultResponse
{
expected
:=
&
ocm
.
LoginProofResultResponse
{
StatusCode
:
200
,
StatusCode
:
200
,
...
@@ -79,3 +149,51 @@ func Test_GetLoginProofResultErr(t *testing.T) {
...
@@ -79,3 +149,51 @@ func Test_GetLoginProofResultErr(t *testing.T) {
assert
.
Error
(
t
,
err
)
assert
.
Error
(
t
,
err
)
assert
.
Contains
(
t
,
err
.
Error
(),
"unexpected response code"
)
assert
.
Contains
(
t
,
err
.
Error
(),
"unexpected response code"
)
}
}
func
Test_GetRawLoginProofResultSuccess
(
t
*
testing
.
T
)
{
expected
:=
map
[
string
]
interface
{}{
"statusCode"
:
float64
(
200
),
"message"
:
"Proof presentation fetch successfully"
,
"data"
:
map
[
string
]
interface
{}{
"state"
:
"done"
,
"presentations"
:
[]
interface
{}{
map
[
string
]
interface
{}{
"schemaId"
:
"7KuDTpQh3GJ7Gp6kErpWvM:2:principalTestSchema:1.0"
,
"credDefId"
:
"7KuDTpQh3GJ7Gp6kErpWvM:3:CL:40329:principalTestCredDefExpire"
,
"revRegId"
:
nil
,
"timestamp"
:
nil
,
"credentialSubject"
:
map
[
string
]
interface
{}{
"email"
:
"23957edb-991d-4b5f-bf76-153103ba45b7"
,
"prcLastName"
:
"NA"
,
},
},
},
},
}
ocmServer
:=
httptest
.
NewServer
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
w
.
WriteHeader
(
http
.
StatusOK
)
_
=
json
.
NewEncoder
(
w
)
.
Encode
(
expected
)
}))
client
:=
ocm
.
New
(
ocmServer
.
URL
)
res
,
err
:=
client
.
GetRawLoginProofResult
(
context
.
Background
(),
"2cf01406-b15f-4960-a6a7-7bc62cd37a3c"
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
expected
[
"statusCode"
],
res
[
"statusCode"
])
assert
.
Equal
(
t
,
expected
[
"message"
],
res
[
"message"
])
assert
.
Equal
(
t
,
expected
[
"data"
],
res
[
"data"
])
}
func
Test_GetRawLoginProofResultErr
(
t
*
testing
.
T
)
{
ocmServer
:=
httptest
.
NewServer
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
w
.
WriteHeader
(
http
.
StatusInternalServerError
)
}))
client
:=
ocm
.
New
(
ocmServer
.
URL
)
res
,
err
:=
client
.
GetRawLoginProofResult
(
context
.
Background
(),
"2cf01406-b15f-4960-a6a7-7bc62cd37a3c"
)
assert
.
Nil
(
t
,
res
)
assert
.
Error
(
t
,
err
)
assert
.
Contains
(
t
,
err
.
Error
(),
"unexpected response code"
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment