Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
policy
Manage
Activity
Members
Labels
Plan
Issues
4
Issue boards
Milestones
Wiki
Code
Merge requests
2
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
policy
Commits
4b6bfc7a
Commit
4b6bfc7a
authored
2 years ago
by
Yordan Kinkov
Browse files
Options
Downloads
Patches
Plain Diff
Handle "scope to credential type" map in GetLoginProofInvitation func
parent
ef338a74
No related branches found
No related tags found
1 merge request
!37
Handle "scope to credential type" map in GetLoginProofInvitation func
Pipeline
#52940
passed with stages
in 1 minute and 21 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
cmd/policy/main.go
+1
-1
1 addition, 1 deletion
cmd/policy/main.go
internal/regofunc/ocm.go
+18
-6
18 additions, 6 deletions
internal/regofunc/ocm.go
internal/regofunc/ocm_test.go
+18
-5
18 additions, 5 deletions
internal/regofunc/ocm_test.go
with
37 additions
and
12 deletions
cmd/policy/main.go
+
1
−
1
View file @
4b6bfc7a
...
...
@@ -96,7 +96,7 @@ func main() {
regofunc
.
Register
(
"issuer"
,
rego
.
FunctionDyn
(
signerFuncs
.
IssuerDID
()))
regofunc
.
Register
(
"createProof"
,
rego
.
Function1
(
signerFuncs
.
CreateProof
()))
regofunc
.
Register
(
"verifyProof"
,
rego
.
Function1
(
signerFuncs
.
VerifyProof
()))
regofunc
.
Register
(
"ocmLoginProofInvitation"
,
rego
.
Function
1
(
ocmFuncs
.
GetLoginProofInvitation
()))
regofunc
.
Register
(
"ocmLoginProofInvitation"
,
rego
.
Function
2
(
ocmFuncs
.
GetLoginProofInvitation
()))
regofunc
.
Register
(
"ocmLoginProofResult"
,
rego
.
Function1
(
ocmFuncs
.
GetLoginProofResult
()))
}
...
...
This diff is collapsed.
Click to expand it.
internal/regofunc/ocm.go
+
18
−
6
View file @
4b6bfc7a
...
...
@@ -21,17 +21,29 @@ func NewOcmFuncs(ocmAddr string, httpClient *http.Client) *OcmFuncs {
return
&
OcmFuncs
{
client
:
ocmClient
}
}
func
(
of
*
OcmFuncs
)
GetLoginProofInvitation
()
(
*
rego
.
Function
,
rego
.
Builtin
1
)
{
func
(
of
*
OcmFuncs
)
GetLoginProofInvitation
()
(
*
rego
.
Function
,
rego
.
Builtin
2
)
{
return
&
rego
.
Function
{
Name
:
"ocm.getLoginProofInvitation"
,
Decl
:
types
.
NewFunction
(
types
.
Args
(
types
.
A
),
types
.
A
),
Decl
:
types
.
NewFunction
(
types
.
Args
(
types
.
A
,
types
.
A
),
types
.
A
),
Memoize
:
true
,
},
func
(
bctx
rego
.
BuiltinContext
,
types
*
ast
.
Term
)
(
*
ast
.
Term
,
error
)
{
var
credTypes
[]
string
func
(
bctx
rego
.
BuiltinContext
,
rScopes
*
ast
.
Term
,
scopesMap
*
ast
.
Term
)
(
*
ast
.
Term
,
error
)
{
var
scopes
[]
string
var
scopeToType
map
[
string
]
string
if
err
:=
ast
.
As
(
rScopes
.
Value
,
&
scopes
);
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"invalid scopes array: %s"
,
err
)
}
else
if
err
=
ast
.
As
(
scopesMap
.
Value
,
&
scopeToType
);
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"invalid scope to credential type map: %s"
,
err
)
}
if
err
:=
ast
.
As
(
types
.
Value
,
&
credTypes
);
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"invalid credential types array: %s"
,
err
)
var
credTypes
[]
string
for
_
,
scope
:=
range
scopes
{
credType
,
ok
:=
scopeToType
[
scope
]
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"scope not found in scope to type map: %s"
,
scope
)
}
credTypes
=
append
(
credTypes
,
credType
)
}
res
,
err
:=
of
.
client
.
GetLoginProofInvitation
(
bctx
.
Context
,
credTypes
)
...
...
This diff is collapsed.
Click to expand it.
internal/regofunc/ocm_test.go
+
18
−
5
View file @
4b6bfc7a
...
...
@@ -33,8 +33,8 @@ func TestGetLoginProofInvitationSuccess(t *testing.T) {
ocmFuncs
:=
regofunc
.
NewOcmFuncs
(
ocmSrv
.
URL
,
http
.
DefaultClient
)
r
:=
rego
.
New
(
rego
.
Query
(
`ocm.getLoginProofInvitation(["openid", "profile"])`
),
rego
.
Function
1
(
ocmFuncs
.
GetLoginProofInvitation
()),
rego
.
Query
(
`ocm.getLoginProofInvitation(["openid", "profile"]
, {"openid": "credType1", "profile": "credType2"}
)`
),
rego
.
Function
2
(
ocmFuncs
.
GetLoginProofInvitation
()),
rego
.
StrictBuiltinErrors
(
true
),
)
...
...
@@ -54,16 +54,29 @@ func TestGetLoginProofInvitationErr(t *testing.T) {
ocmFuncs
:=
regofunc
.
NewOcmFuncs
(
ocmSrv
.
URL
,
http
.
DefaultClient
)
// invalid scopes array
r
:=
rego
.
New
(
rego
.
Query
(
`ocm.getLoginProofInvitation("openid")`
),
rego
.
Function
1
(
ocmFuncs
.
GetLoginProofInvitation
()),
rego
.
Query
(
`ocm.getLoginProofInvitation("openid"
, {"openid": "credType1", "profile": "credType2"}
)`
),
rego
.
Function
2
(
ocmFuncs
.
GetLoginProofInvitation
()),
rego
.
StrictBuiltinErrors
(
true
),
)
resultSet
,
err
:=
r
.
Eval
(
context
.
Background
())
assert
.
Error
(
t
,
err
)
assert
.
Empty
(
t
,
resultSet
)
assert
.
Contains
(
t
,
err
.
Error
(),
"cannot unmarshal string into Go value of type []string"
)
assert
.
Contains
(
t
,
err
.
Error
(),
"invalid scopes array"
)
// invalid "scope to credential type" map
r
=
rego
.
New
(
rego
.
Query
(
`ocm.getLoginProofInvitation(["openid", "profile"], "map")`
),
rego
.
Function2
(
ocmFuncs
.
GetLoginProofInvitation
()),
rego
.
StrictBuiltinErrors
(
true
),
)
resultSet
,
err
=
r
.
Eval
(
context
.
Background
())
assert
.
Error
(
t
,
err
)
assert
.
Empty
(
t
,
resultSet
)
assert
.
Contains
(
t
,
err
.
Error
(),
"invalid scope to credential type map"
)
}
func
TestGetLoginProofResult
(
t
*
testing
.
T
)
{
...
...
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