Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
keycloak-proxy
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
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Janne Mareike Koschinski
keycloak-proxy
Commits
e4942665
Commit
e4942665
authored
Dec 17, 2015
by
Rohith
Browse files
Options
Downloads
Patches
Plain Diff
- adding the additional tests for the session.go
- fixing up the preferred_username claim
parent
13880bee
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
session.go
+1
-1
1 addition, 1 deletion
session.go
session_test.go
+57
-0
57 additions, 0 deletions
session_test.go
with
58 additions
and
1 deletion
session.go
+
1
−
1
View file @
e4942665
...
@@ -105,7 +105,7 @@ func (r *KeycloakProxy) getUserContext(token jose.JWT) (*UserContext, error) {
...
@@ -105,7 +105,7 @@ func (r *KeycloakProxy) getUserContext(token jose.JWT) (*UserContext, error) {
}
}
// step: get the preferred name
// step: get the preferred name
preferredName
,
_
,
err
:=
claims
.
StringClaim
(
"preferred_name"
)
preferredName
,
_
,
err
:=
claims
.
StringClaim
(
"preferred_
user
name"
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Warningf
(
"unable to extract the preferred name from the token claims, reason: %s"
,
err
)
glog
.
Warningf
(
"unable to extract the preferred name from the token claims, reason: %s"
,
err
)
}
}
...
...
This diff is collapsed.
Click to expand it.
session_test.go
+
57
−
0
View file @
e4942665
...
@@ -18,12 +18,69 @@ package main
...
@@ -18,12 +18,69 @@ package main
import
(
import
(
"testing"
"testing"
"time"
"time"
"reflect"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
"github.com/gambol99/go-oidc/jose"
)
)
func
TestGetUserContext
(
t
*
testing
.
T
)
{
func
TestGetUserContext
(
t
*
testing
.
T
)
{
proxy
:=
newFakeKeycloakProxy
(
t
)
testToken
,
err
:=
jose
.
NewJWT
(
jose
.
JOSEHeader
{
"alg"
:
"RS256"
,
},
jose
.
Claims
{
"jti"
:
"4ee75b8e-3ee6-4382-92d4-3390b4b4937b"
,
//"exp": "1450372969",
"nbf"
:
0
,
"iat"
:
"1450372669"
,
"iss"
:
"https://keycloak.example.com/auth/realms/commons"
,
"aud"
:
"test"
,
"sub"
:
"1e11e539-8256-4b3b-bda8-cc0d56cddb48"
,
"typ"
:
"Bearer"
,
"azp"
:
"clientid"
,
"session_state"
:
"98f4c3d2-1b8c-4932-b8c4-92ec0ea7e195"
,
"client_session"
:
"f0105893-369a-46bc-9661-ad8c747b1a69"
,
"resource_access"
:
map
[
string
]
interface
{}{
"openvpn"
:
map
[
string
]
interface
{}{
"roles"
:
[]
string
{
"vpn-user"
,
"dev-vpn"
,
},
},
"account"
:
map
[
string
]
interface
{}{
"roles"
:
[]
string
{
"view-profile"
,
"manage-account"
,
},
},
},
"email"
:
"gambol99@gmail.com"
,
"name"
:
"Rohith Jayawardene"
,
"family_name"
:
"Jayawardene"
,
"preferred_username"
:
"rjayawardene"
,
"given_name"
:
"Rohith"
,
})
if
assert
.
NoError
(
t
,
err
,
"should not have recieved an error parsing the token"
)
{
t
.
Failed
()
}
if
!
assert
.
NotNil
(
t
,
testToken
,
"should not have got nil from token"
)
{
t
.
FailNow
()
}
context
,
err
:=
proxy
.
getUserContext
(
testToken
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
context
)
assert
.
Equal
(
t
,
"1e11e539-8256-4b3b-bda8-cc0d56cddb48"
,
context
.
id
)
assert
.
Equal
(
t
,
"gambol99@gmail.com"
,
context
.
email
)
assert
.
Equal
(
t
,
"rjayawardene"
,
context
.
preferredName
)
roles
:=
[]
string
{
"account:view-profile"
,
"account:manage-account"
,
"openvpn:vpn-user"
,
"openvpn:dev-vpn"
}
if
!
reflect
.
DeepEqual
(
context
.
roles
,
roles
)
{
t
.
Errorf
(
"the claims are not the same, %v <-> %v"
,
context
.
roles
,
roles
)
}
}
}
func
TestEncodeState
(
t
*
testing
.
T
)
{
func
TestEncodeState
(
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