Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
id
go-sso
Commits
79a14158
Commit
79a14158
authored
Dec 20, 2019
by
ale
Browse files
Improve keystore test
parent
7417d7d5
Changes
1
Hide whitespace changes
Inline
Side-by-side
server/http_test.go
View file @
79a14158
...
...
@@ -69,12 +69,12 @@ func startTestHTTPServer(t testing.TB) (string, *httptest.Server) {
return
tmpdir
,
srv
}
func
startTestHTTPServerWithKeyStore
(
t
testing
.
TB
)
(
string
,
*
httptest
.
Server
)
{
func
startTestHTTPServerWithKeyStore
(
t
testing
.
TB
)
(
string
,
*
httptest
.
Server
,
*
fakeKeyStore
)
{
ks
:=
createFakeKeyStore
(
t
,
"testuser"
,
"password"
)
tmpdir
,
_
:=
ioutil
.
TempDir
(
""
,
""
)
config
:=
testConfig
(
t
,
tmpdir
,
ks
.
URL
)
return
tmpdir
,
createTestHTTPServer
(
t
,
config
)
return
tmpdir
,
createTestHTTPServer
(
t
,
config
)
,
ks
}
func
makeHTTPClient
(
dnsOverrides
map
[
string
]
string
,
followExternalRedirects
bool
)
*
http
.
Client
{
...
...
@@ -453,7 +453,13 @@ func TestHTTP_LoginOTP_Intermediate404(t *testing.T) {
doPostForm
(
t
,
c
,
httpSrv
.
URL
+
"/login/otp"
,
v
,
checkRedirectToTargetService
)
}
func
createFakeKeyStore
(
t
testing
.
TB
,
username
,
password
string
)
*
httptest
.
Server
{
type
fakeKeyStore
struct
{
*
httptest
.
Server
values
map
[
string
]
string
}
func
createFakeKeyStore
(
t
testing
.
TB
,
username
,
password
string
)
*
fakeKeyStore
{
values
:=
make
(
map
[
string
]
string
)
h
:=
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
if
req
.
URL
.
Path
!=
"/api/open"
{
http
.
NotFound
(
w
,
req
)
...
...
@@ -464,20 +470,18 @@ func createFakeKeyStore(t testing.TB, username, password string) *httptest.Serve
t
.
Errorf
(
"bad JSON body: %v"
,
err
)
return
}
if
openReq
.
Username
!=
username
{
t
.
Errorf
(
"bad username in keystore Open request: expected %s, got %s"
,
username
,
openReq
.
Username
)
}
if
openReq
.
Password
!=
password
{
t
.
Errorf
(
"bad password in keystore Open request: expected %s, got %s"
,
password
,
openReq
.
Password
)
}
values
[
openReq
.
Username
]
=
openReq
.
Password
w
.
Header
()
.
Set
(
"Content-Type"
,
"application/json"
)
io
.
WriteString
(
w
,
"{}"
)
// nolint
})
return
httptest
.
NewServer
(
h
)
return
&
fakeKeyStore
{
Server
:
httptest
.
NewServer
(
h
),
values
:
values
,
}
}
func
TestHTTP_LoginWithKeyStore
(
t
*
testing
.
T
)
{
tmpdir
,
httpSrv
:=
startTestHTTPServerWithKeyStore
(
t
)
tmpdir
,
httpSrv
,
ks
:=
startTestHTTPServerWithKeyStore
(
t
)
defer
os
.
RemoveAll
(
tmpdir
)
defer
httpSrv
.
Close
()
...
...
@@ -497,6 +501,11 @@ func TestHTTP_LoginWithKeyStore(t *testing.T) {
v
.
Set
(
"username"
,
"testuser"
)
v
.
Set
(
"password"
,
"password"
)
doPostForm
(
t
,
c
,
httpSrv
.
URL
+
"/login"
,
v
,
checkRedirectToTargetService
)
// Verify that the keystore has been called.
if
v
:=
ks
.
values
[
"testuser"
];
v
!=
"password"
{
t
.
Fatalf
(
"keystore not called as expected: ks_values=%+v"
,
ks
.
values
)
}
}
func
TestHTTP_CORS
(
t
*
testing
.
T
)
{
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment