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
29701d98
Commit
29701d98
authored
5 years ago
by
Christian Pointner
Browse files
Options
Downloads
Patches
Plain Diff
test for delete session
parent
b2adec62
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
auth/auth_test.go
+47
-0
47 additions, 0 deletions
auth/auth_test.go
with
47 additions
and
0 deletions
auth/auth_test.go
+
47
−
0
View file @
29701d98
...
...
@@ -214,6 +214,7 @@ func TestAuthBearerToken(t *testing.T) {
{
"Bearer invalid"
,
http
.
StatusUnauthorized
},
{
"Bearer invalid:"
,
http
.
StatusUnauthorized
},
{
"Bearer unknown:secret"
,
http
.
StatusUnauthorized
},
{
"Bearer "
+
s
.
id
+
":invalid"
,
http
.
StatusUnauthorized
},
{
"Bearer "
+
s
.
getToken
(),
http
.
StatusOK
},
}
...
...
@@ -302,3 +303,49 @@ func TestAuthWaitForLogin(t *testing.T) {
}
}
}
func
TestAuthDeleteSession
(
t
*
testing
.
T
)
{
cfg
:=
&
Config
{}
if
err
:=
Init
(
cfg
,
nil
,
nil
,
nil
);
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
if
auth
.
sessions
==
nil
{
t
.
Fatalf
(
"authentication should be enabled but Init created no session manager"
)
}
s
,
err
:=
NewSession
()
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
if
err
=
auth
.
sessions
.
insert
(
s
);
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
router
:=
mux
.
NewRouter
()
InstallHTTPHandler
(
router
)
req
,
err
:=
http
.
NewRequest
(
"DELETE"
,
"/session"
,
nil
)
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
rr
:=
httptest
.
NewRecorder
()
router
.
ServeHTTP
(
rr
,
req
)
if
rr
.
Code
!=
http
.
StatusUnauthorized
{
t
.
Fatalf
(
"unexpected reponse code: %d (%s)"
,
rr
.
Code
,
http
.
StatusText
(
rr
.
Code
))
}
if
req
,
err
=
http
.
NewRequest
(
"DELETE"
,
"/session"
,
nil
);
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
req
.
Header
.
Set
(
"Authorization"
,
"Bearer "
+
s
.
getToken
())
rr
=
httptest
.
NewRecorder
()
router
.
ServeHTTP
(
rr
,
req
)
if
rr
.
Code
!=
http
.
StatusOK
{
t
.
Fatalf
(
"unexpected reponse code: %d (%s)"
,
rr
.
Code
,
http
.
StatusText
(
rr
.
Code
))
}
if
len
(
auth
.
sessions
.
sessions
)
!=
0
{
t
.
Fatalf
(
"session wasn't removed from session manager"
)
}
}
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