Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
tank
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AURA
tank
Commits
938a89e4
Commit
938a89e4
authored
5 years ago
by
Christian Pointner
Browse files
Options
Downloads
Patches
Plain Diff
some more session test-cases
parent
983ffdad
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
auth/oidc.go
+1
-1
1 addition, 1 deletion
auth/oidc.go
auth/sessions.go
+4
-4
4 additions, 4 deletions
auth/sessions.go
auth/sessions_test.go
+59
-0
59 additions, 0 deletions
auth/sessions_test.go
with
64 additions
and
5 deletions
auth/oidc.go
+
1
−
1
View file @
938a89e4
...
...
@@ -55,7 +55,7 @@ func (os *OIDCSession) refresh(ctx context.Context, in *Session) (*Session, erro
if
err
:=
userInfo
.
Claims
(
out
);
err
!=
nil
{
return
nil
,
errors
.
New
(
"parsing OIDC UserInfo failed: "
+
err
.
Error
())
}
if
err
=
auth
.
sessions
.
update
(
in
.
ID
(),
out
);
err
!=
nil
{
if
err
=
auth
.
sessions
.
update
(
out
);
err
!=
nil
{
return
nil
,
errors
.
New
(
"updating session failed: "
+
err
.
Error
())
}
return
out
,
nil
...
...
This diff is collapsed.
Click to expand it.
auth/sessions.go
+
4
−
4
View file @
938a89e4
...
...
@@ -324,11 +324,11 @@ func (sm *SessionManager) getAndSubscribe(id string) (*Session, <-chan struct{})
return
s
,
s
.
subscribe
()
}
func
(
sm
*
SessionManager
)
update
(
id
string
,
s
*
Session
)
error
{
func
(
sm
*
SessionManager
)
update
(
s
*
Session
)
error
{
sm
.
mutex
.
Lock
()
defer
sm
.
mutex
.
Unlock
()
old
,
ok
:=
sm
.
sessions
[
id
]
old
,
ok
:=
sm
.
sessions
[
s
.
id
]
if
!
ok
{
return
errors
.
New
(
"session not found."
)
}
...
...
@@ -338,9 +338,9 @@ func (sm *SessionManager) update(id string, s *Session) error {
old
.
signalSubscribers
()
sm
.
sessions
[
id
]
=
s
sm
.
sessions
[
s
.
id
]
=
s
old
.
setState
(
SessionStateStale
)
auth
.
dbgLog
.
Printf
(
"authentication: updated session %s"
,
id
)
auth
.
dbgLog
.
Printf
(
"authentication: updated session %s"
,
s
.
id
)
return
nil
}
...
...
This diff is collapsed.
Click to expand it.
auth/sessions_test.go
+
59
−
0
View file @
938a89e4
...
...
@@ -44,6 +44,65 @@ func TestCreateSessionManager(t *testing.T) {
}
}
func
TestSessionNewAndUpdate
(
t
*
testing
.
T
)
{
sm
,
err
:=
NewSessionManager
(
SessionsConfig
{})
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
s1
,
err
:=
sm
.
new
()
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
if
err
=
sm
.
update
(
&
Session
{
id
:
"unknown"
});
err
==
nil
{
t
.
Fatalf
(
"updating non-existing session should fail"
)
}
s2
:=
s1
.
emptyCopy
()
s2
.
Username
=
"foo"
if
err
=
sm
.
update
(
s2
);
err
!=
nil
{
t
.
Fatalf
(
"updating session failed: %v"
,
err
)
}
}
func
TestSessionCleanup
(
t
*
testing
.
T
)
{
sm
,
err
:=
NewSessionManager
(
SessionsConfig
{})
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
s1
,
err
:=
sm
.
new
()
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
if
!
s1
.
updateState
(
SessionStateNew
,
SessionStateLoggedOut
)
{
t
.
Fatalf
(
"updating session state should have worked"
)
}
s2
,
err
:=
sm
.
new
()
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
s3
,
err
:=
sm
.
new
()
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
s3
.
cancel
()
sm
.
cleanup
()
if
sm
.
get
(
s1
.
id
)
!=
nil
||
sm
.
get
(
s3
.
id
)
!=
nil
{
t
.
Fatalf
(
"dead sessions should have been cleaned up"
)
}
if
sm
.
get
(
s2
.
id
)
!=
s2
{
t
.
Fatalf
(
"alive sessions shouldn't have been cleaned up"
)
}
}
func
TestSessionExpiry
(
t
*
testing
.
T
)
{
cfg
:=
SessionsConfig
{}
cfg
.
MaxAge
=
time
.
Second
...
...
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