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
24db1ed4
Commit
24db1ed4
authored
Sep 29, 2016
by
Rohith
Committed by
GitHub
Sep 29, 2016
Browse files
Options
Downloads
Patches
Plain Diff
- fixing the --cookie-domain option (#137)
- adding extra test for verify the cookie domain is working correctly
parent
90c447c1
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
cli.go
+1
-1
1 addition, 1 deletion
cli.go
cookies_test.go
+34
-0
34 additions, 0 deletions
cookies_test.go
server_test.go
+25
-16
25 additions, 16 deletions
server_test.go
with
60 additions
and
17 deletions
cli.go
+
1
−
1
View file @
24db1ed4
...
@@ -179,7 +179,7 @@ func getCLIOptions() []cli.Flag {
...
@@ -179,7 +179,7 @@ func getCLIOptions() []cli.Flag {
Name
:
"http-only-cookie"
,
Name
:
"http-only-cookie"
,
Usage
:
"enforces the cookie is in http only mode, default to false"
,
Usage
:
"enforces the cookie is in http only mode, default to false"
,
},
},
cli
.
String
Slice
Flag
{
cli
.
StringFlag
{
Name
:
"cookie-domain"
,
Name
:
"cookie-domain"
,
Usage
:
"a domain the access cookie is available to, defaults host header"
,
Usage
:
"a domain the access cookie is available to, defaults host header"
,
},
},
...
...
This diff is collapsed.
Click to expand it.
cookies_test.go
+
34
−
0
View file @
24db1ed4
...
@@ -16,11 +16,45 @@ limitations under the License.
...
@@ -16,11 +16,45 @@ limitations under the License.
package
main
package
main
import
(
import
(
"net/http"
"testing"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
)
)
func
TestCookieDomainHostHeader
(
t
*
testing
.
T
)
{
svc
:=
newTestService
()
resp
,
err
:=
makeTestCodeFlowLogin
(
svc
+
"/admin"
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
resp
)
var
cookie
*
http
.
Cookie
for
_
,
c
:=
range
resp
.
Cookies
()
{
if
c
.
Name
==
"kc-access"
{
cookie
=
c
}
}
assert
.
NotNil
(
t
,
cookie
)
assert
.
Equal
(
t
,
cookie
.
Domain
,
"127.0.0.1"
)
}
func
TestCookieDomain
(
t
*
testing
.
T
)
{
p
,
_
,
svc
:=
newTestProxyService
(
nil
)
p
.
config
.
CookieDomain
=
"domain.com"
resp
,
err
:=
makeTestCodeFlowLogin
(
svc
+
"/admin"
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
resp
)
var
cookie
*
http
.
Cookie
for
_
,
c
:=
range
resp
.
Cookies
()
{
if
c
.
Name
==
"kc-access"
{
cookie
=
c
}
}
assert
.
NotNil
(
t
,
cookie
)
assert
.
Equal
(
t
,
cookie
.
Domain
,
"domain.com"
)
}
func
TestDropCookie
(
t
*
testing
.
T
)
{
func
TestDropCookie
(
t
*
testing
.
T
)
{
p
,
_
,
_
:=
newTestProxyService
(
nil
)
p
,
_
,
_
:=
newTestProxyService
(
nil
)
...
...
This diff is collapsed.
Click to expand it.
server_test.go
+
25
−
16
View file @
24db1ed4
...
@@ -269,39 +269,48 @@ func newFakeGinContext(method, uri string) *gin.Context {
...
@@ -269,39 +269,48 @@ func newFakeGinContext(method, uri string) *gin.Context {
// makeTestOauthLogin performs a fake oauth login into the service, retrieving the access token
// makeTestOauthLogin performs a fake oauth login into the service, retrieving the access token
func
makeTestOauthLogin
(
location
string
)
(
string
,
error
)
{
func
makeTestOauthLogin
(
location
string
)
(
string
,
error
)
{
u
,
err
:=
url
.
Parse
(
location
)
resp
,
err
:=
makeTestCodeFlowLogin
(
location
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
}
}
// step: check the cookie is there
for
_
,
c
:=
range
resp
.
Cookies
()
{
if
c
.
Name
==
"kc-access"
{
return
c
.
Value
,
nil
}
}
return
""
,
errors
.
New
(
"access cookie not found in response from oauth service"
)
}
func
makeTestCodeFlowLogin
(
location
string
)
(
*
http
.
Response
,
error
)
{
u
,
err
:=
url
.
Parse
(
location
)
if
err
!=
nil
{
return
nil
,
err
}
// step: get the redirect
// step: get the redirect
var
resp
onse
*
http
.
Response
var
resp
*
http
.
Response
for
count
:=
0
;
count
<
4
;
count
++
{
for
count
:=
0
;
count
<
4
;
count
++
{
req
,
err
:=
http
.
NewRequest
(
"GET"
,
location
,
nil
)
req
,
err
:=
http
.
NewRequest
(
"GET"
,
location
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
nil
,
err
}
}
// step: make the request
// step: make the request
resp
onse
,
err
=
http
.
DefaultTransport
.
RoundTrip
(
req
)
resp
,
err
=
http
.
DefaultTransport
.
RoundTrip
(
req
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
nil
,
err
}
}
if
resp
onse
.
StatusCode
!=
http
.
StatusTemporaryRedirect
{
if
resp
.
StatusCode
!=
http
.
StatusTemporaryRedirect
{
return
""
,
errors
.
New
(
"no redirection found in resp
onse
"
)
return
nil
,
errors
.
New
(
"no redirection found in resp"
)
}
}
location
=
resp
onse
.
Header
.
Get
(
"Location"
)
location
=
resp
.
Header
.
Get
(
"Location"
)
if
!
strings
.
HasPrefix
(
location
,
"http"
)
{
if
!
strings
.
HasPrefix
(
location
,
"http"
)
{
location
=
fmt
.
Sprintf
(
"%s://%s%s"
,
u
.
Scheme
,
u
.
Host
,
location
)
location
=
fmt
.
Sprintf
(
"%s://%s%s"
,
u
.
Scheme
,
u
.
Host
,
location
)
}
}
}
}
// step: check the cookie is there
return
resp
,
nil
for
_
,
c
:=
range
response
.
Cookies
()
{
if
c
.
Name
==
"kc-access"
{
return
c
.
Value
,
nil
}
}
return
""
,
errors
.
New
(
"access cookie not found in response from oauth service"
)
}
}
func
newFakeGinContextWithCookies
(
method
,
url
string
,
cookies
[]
*
http
.
Cookie
)
*
gin
.
Context
{
func
newFakeGinContextWithCookies
(
method
,
url
string
,
cookies
[]
*
http
.
Cookie
)
*
gin
.
Context
{
...
...
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