Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
go-sso
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
id
go-sso
Commits
7ab9e359
Commit
7ab9e359
authored
5 years ago
by
ale
Committed by
godog
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add tests for the /exchange HTTP endpoint
parent
ad26ddab
No related branches found
No related tags found
No related merge requests found
Pipeline
#5404
failed
5 years ago
Stage: build_pkgsrc
Stage: build_pkg
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
server/http_test.go
+49
-1
49 additions, 1 deletion
server/http_test.go
server/service_test.go
+4
-2
4 additions, 2 deletions
server/service_test.go
with
53 additions
and
3 deletions
server/http_test.go
+
49
−
1
View file @
7ab9e359
...
@@ -142,12 +142,18 @@ func checkStatusOk(t testing.TB, resp *http.Response) {
...
@@ -142,12 +142,18 @@ func checkStatusOk(t testing.TB, resp *http.Response) {
}
}
}
}
func
checkStatusForbidden
(
t
testing
.
TB
,
resp
*
http
.
Response
)
{
if
resp
.
StatusCode
!=
403
{
t
.
Fatalf
(
"expected status 403, got %s"
,
resp
.
Status
)
}
}
func
checkStatusNotFound
(
t
testing
.
TB
,
resp
*
http
.
Response
)
{
func
checkStatusNotFound
(
t
testing
.
TB
,
resp
*
http
.
Response
)
{
if
resp
.
StatusCode
!=
404
{
if
resp
.
StatusCode
!=
404
{
t
.
Fatalf
(
"expected status 404, got %s"
,
resp
.
Status
)
t
.
Fatalf
(
"expected status 404, got %s"
,
resp
.
Status
)
}
}
}
}
func
checkRedirectToTargetService
(
t
testing
.
TB
,
resp
*
http
.
Response
)
{
func
checkRedirectToTargetService
(
t
testing
.
TB
,
resp
*
http
.
Response
)
{
if
resp
.
StatusCode
!=
302
{
if
resp
.
StatusCode
!=
302
{
t
.
Fatalf
(
"expected status 302, got %s"
,
resp
.
Status
)
t
.
Fatalf
(
"expected status 302, got %s"
,
resp
.
Status
)
...
@@ -424,3 +430,45 @@ func TestHTTP_CORS(t *testing.T) {
...
@@ -424,3 +430,45 @@ func TestHTTP_CORS(t *testing.T) {
t
.
Fatalf
(
"Bad Access-Control-Allow-Origin returned to OPTIONS request: %s"
,
s
)
t
.
Fatalf
(
"Bad Access-Control-Allow-Origin returned to OPTIONS request: %s"
,
s
)
}
}
}
}
func
TestHTTP_LoginAndExchange
(
t
*
testing
.
T
)
{
tmpdir
,
httpSrv
:=
startTestHTTPServer
(
t
)
defer
os
.
RemoveAll
(
tmpdir
)
defer
httpSrv
.
Close
()
c
:=
newTestHTTPClient
()
// Simulate an authorization request from a service, expect to
// see the login page.
v
:=
make
(
url
.
Values
)
v
.
Set
(
"s"
,
"service.example.com/"
)
v
.
Set
(
"d"
,
"https://service.example.com/admin/"
)
v
.
Set
(
"n"
,
"averysecretnonce"
)
doGet
(
t
,
c
,
httpSrv
.
URL
+
"/?"
+
v
.
Encode
(),
checkStatusOk
,
checkLoginPageURL
,
checkLoginPasswordPage
)
// Attempt to login by submitting the form. We expect the
// result to be a 302 redirect to the target service.
v
=
make
(
url
.
Values
)
v
.
Set
(
"username"
,
"testuser"
)
v
.
Set
(
"password"
,
"password"
)
var
ssoTkt
string
doPostForm
(
t
,
c
,
httpSrv
.
URL
+
"/login"
,
v
,
checkRedirectToTargetService
,
extractSSOTicket
(
&
ssoTkt
))
// Make an exchange request for a new service.
v
=
make
(
url
.
Values
)
v
.
Set
(
"cur_tkt"
,
ssoTkt
)
v
.
Set
(
"cur_svc"
,
"service.example.com/"
)
v
.
Set
(
"cur_nonce"
,
"averysecretnonce"
)
v
.
Set
(
"new_svc"
,
"service2.example.com/"
)
v
.
Set
(
"new_nonce"
,
"anothernonce"
)
doPostForm
(
t
,
c
,
httpSrv
.
URL
+
"/exchange"
,
v
,
checkStatusOk
)
// Make an exchange request for a forbidden service.
v
=
make
(
url
.
Values
)
v
.
Set
(
"cur_tkt"
,
ssoTkt
)
v
.
Set
(
"cur_svc"
,
"service.example.com/"
)
v
.
Set
(
"cur_nonce"
,
"averysecretnonce"
)
v
.
Set
(
"new_svc"
,
"service3.example.com/"
)
v
.
Set
(
"new_nonce"
,
"anothernonce"
)
doPostForm
(
t
,
c
,
httpSrv
.
URL
+
"/exchange"
,
v
,
checkStatusForbidden
)
}
This diff is collapsed.
Click to expand it.
server/service_test.go
+
4
−
2
View file @
7ab9e359
...
@@ -39,9 +39,10 @@ domain: example.com
...
@@ -39,9 +39,10 @@ domain: example.com
allowed_services:
allowed_services:
- "^service\\.example\\.com/$"
- "^service\\.example\\.com/$"
- "^service2\\.example\\.com/$"
- "^service2\\.example\\.com/$"
- "^service3\\.example\\.com/$"
allowed_exchanges:
allowed_exchanges:
- src_regexp: "^service\\.example\\.com/$"
- src_regexp: "^service\\.example\\.com/$"
dst_regexp: "\\.example\\.com/
.*
$"
dst_regexp: "
^service2
\\.example\\.com/$"
allowed_cors_origins:
allowed_cors_origins:
- "https://origin.example.com"
- "https://origin.example.com"
service_ttls:
service_ttls:
...
@@ -139,9 +140,10 @@ func TestLoginService_Exchange(t *testing.T) {
...
@@ -139,9 +140,10 @@ func TestLoginService_Exchange(t *testing.T) {
service
,
destination
string
service
,
destination
string
ok
bool
ok
bool
}{
}{
{
"service.example.com/"
,
"service.example.com/"
,
false
},
{
"service.example.com/"
,
"service2.example.com/"
,
true
},
{
"service.example.com/"
,
"service2.example.com/"
,
true
},
{
"service.example.com/"
,
"service3.example.com/"
,
false
},
{
"service.example.com/"
,
"bad-service.another.com/"
,
false
},
{
"service.example.com/"
,
"bad-service.another.com/"
,
false
},
{
"service.example.com/"
,
"service.example.com/"
,
true
},
// self-exchange??
}
}
for
_
,
td
:=
range
testdata
{
for
_
,
td
:=
range
testdata
{
...
...
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