Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
policy
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
policy
Commits
00dbbd82
Commit
00dbbd82
authored
2 years ago
by
Yordan Kinkov
Browse files
Options
Downloads
Patches
Plain Diff
#45
remove duplicate types in GetLoginProogInvitation ext function
parent
8b61235c
No related branches found
No related tags found
1 merge request
!41
Remove duplicate types in GetLoginProogInvitation ext function
Pipeline
#53424
passed
2 years ago
Stage: test
Stage: build
Stage: manifest
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
internal/regofunc/ocm.go
+9
-1
9 additions, 1 deletion
internal/regofunc/ocm.go
internal/regofunc/ocm_test.go
+27
-0
27 additions, 0 deletions
internal/regofunc/ocm_test.go
with
36 additions
and
1 deletion
internal/regofunc/ocm.go
+
9
−
1
View file @
00dbbd82
...
...
@@ -38,12 +38,20 @@ func (of *OcmFuncs) GetLoginProofInvitation() (*rego.Function, rego.Builtin2) {
}
var
credTypes
[]
string
distinctTypes
:=
make
(
map
[
string
]
bool
,
len
(
scopeToType
))
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
)
if
credType
!=
""
&&
!
distinctTypes
[
credType
]
{
credTypes
=
append
(
credTypes
,
credType
)
}
distinctTypes
[
credType
]
=
true
}
if
len
(
credTypes
)
==
0
{
return
nil
,
fmt
.
Errorf
(
"no credential types found in the scope to type map: %s"
,
scopeToType
)
}
res
,
err
:=
of
.
client
.
GetLoginProofInvitation
(
bctx
.
Context
,
credTypes
)
...
...
This diff is collapsed.
Click to expand it.
internal/regofunc/ocm_test.go
+
27
−
0
View file @
00dbbd82
...
...
@@ -44,6 +44,20 @@ func TestGetLoginProofInvitationSuccess(t *testing.T) {
resultBytes
,
err
:=
json
.
Marshal
(
resultSet
[
0
]
.
Expressions
[
0
]
.
Value
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
expected
,
string
(
resultBytes
))
// "scope to credential type" map with duplicate and empty credential types
r
=
rego
.
New
(
rego
.
Query
(
`ocm.getLoginProofInvitation(["openid", "profile", "email"], {"openid": "credType1", "profile": "credType1", "email": ""})`
),
rego
.
Function2
(
ocmFuncs
.
GetLoginProofInvitation
()),
rego
.
StrictBuiltinErrors
(
true
),
)
resultSet
,
err
=
r
.
Eval
(
context
.
Background
())
assert
.
NoError
(
t
,
err
)
resultBytes
,
err
=
json
.
Marshal
(
resultSet
[
0
]
.
Expressions
[
0
]
.
Value
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
expected
,
string
(
resultBytes
))
}
func
TestGetLoginProofInvitationErr
(
t
*
testing
.
T
)
{
...
...
@@ -77,6 +91,19 @@ func TestGetLoginProofInvitationErr(t *testing.T) {
assert
.
Error
(
t
,
err
)
assert
.
Empty
(
t
,
resultSet
)
assert
.
Contains
(
t
,
err
.
Error
(),
"invalid scope to credential type map"
)
// empty types in "scope to credential type" map
r
=
rego
.
New
(
rego
.
Query
(
`ocm.getLoginProofInvitation(["openid", "profile"], {"openid": "", "profile": ""})`
),
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
(),
"no credential types found in the scope to 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