Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dex
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
dex
Commits
a33d61c8
Commit
a33d61c8
authored
Jun 06, 2016
by
Bobby Rullo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
server: remove boilerplate setup code part deux
Use the test fixture setup stuff in testutil instead.
parent
ad1d5ab2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
75 deletions
+39
-75
client_resource_test.go
server/client_resource_test.go
+7
-13
http_test.go
server/http_test.go
+12
-55
testutil.go
server/testutil.go
+20
-7
No files found.
server/client_resource_test.go
View file @
a33d61c8
...
...
@@ -188,7 +188,7 @@ func TestList(t *testing.T) {
}{
// empty repo
{
cs
:
nil
,
cs
:
[]
client
.
Client
{}
,
want
:
nil
,
},
// single client
...
...
@@ -244,20 +244,14 @@ func TestList(t *testing.T) {
}
for
i
,
tt
:=
range
tests
{
dbm
:=
db
.
NewMemDB
()
clientIDGenerator
:=
func
(
hostport
string
)
(
string
,
error
)
{
return
hostport
,
nil
}
secGen
:=
func
()
([]
byte
,
error
)
{
return
[]
byte
(
"secret"
),
nil
}
clientRepo
:=
db
.
NewClientRepo
(
dbm
)
clientManager
,
err
:=
manager
.
NewClientManagerFromClients
(
clientRepo
,
db
.
TransactionFactory
(
dbm
),
tt
.
cs
,
manager
.
ManagerOptions
{
ClientIDGenerator
:
clientIDGenerator
,
SecretGenerator
:
secGen
})
f
,
err
:=
makeTestFixturesWithOptions
(
testFixtureOptions
{
clients
:
tt
.
cs
,
})
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to create client identity manager: %v"
,
err
)
continue
t
.
Fatalf
(
"error making test fixtures: %v"
,
err
)
}
res
:=
&
clientResource
{
manager
:
clientManager
}
res
:=
&
clientResource
{
manager
:
f
.
clientManager
}
r
,
err
:=
http
.
NewRequest
(
"GET"
,
"http://example.com/clients"
,
nil
)
if
err
!=
nil
{
...
...
server/http_test.go
View file @
a33d61c8
...
...
@@ -17,10 +17,7 @@ import (
"github.com/jonboulle/clockwork"
"github.com/coreos/dex/client"
clientmanager
"github.com/coreos/dex/client/manager"
"github.com/coreos/dex/connector"
"github.com/coreos/dex/db"
"github.com/coreos/dex/session/manager"
"github.com/coreos/go-oidc/jose"
"github.com/coreos/go-oidc/oauth2"
"github.com/coreos/go-oidc/oidc"
...
...
@@ -76,38 +73,6 @@ func TestHandleAuthFuncResponsesSingleRedirectURL(t *testing.T) {
idpcs
:=
[]
connector
.
Connector
{
&
fakeConnector
{
loginURL
:
"http://fake.example.com"
},
}
dbm
:=
db
.
NewMemDB
()
clients
:=
[]
client
.
Client
{
client
.
Client
{
Credentials
:
oidc
.
ClientCredentials
{
ID
:
"client.example.com"
,
Secret
:
base64
.
URLEncoding
.
EncodeToString
([]
byte
(
"secret"
)),
},
Metadata
:
oidc
.
ClientMetadata
{
RedirectURIs
:
[]
url
.
URL
{
url
.
URL
{
Scheme
:
"http"
,
Host
:
"client.example.com"
,
Path
:
"/callback"
},
},
},
},
}
clientIDGenerator
:=
func
(
hostport
string
)
(
string
,
error
)
{
return
hostport
,
nil
}
secGen
:=
func
()
([]
byte
,
error
)
{
return
[]
byte
(
"secret"
),
nil
}
clientRepo
:=
db
.
NewClientRepo
(
dbm
)
clientManager
,
err
:=
clientmanager
.
NewClientManagerFromClients
(
clientRepo
,
db
.
TransactionFactory
(
dbm
),
clients
,
clientmanager
.
ManagerOptions
{
ClientIDGenerator
:
clientIDGenerator
,
SecretGenerator
:
secGen
})
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to create client identity manager: %v"
,
err
)
}
srv
:=
&
Server
{
IssuerURL
:
url
.
URL
{
Scheme
:
"http"
,
Host
:
"server.example.com"
},
SessionManager
:
manager
.
NewSessionManager
(
db
.
NewSessionRepo
(
db
.
NewMemDB
()),
db
.
NewSessionKeyRepo
(
db
.
NewMemDB
())),
ClientRepo
:
clientRepo
,
ClientManager
:
clientManager
,
}
tests
:=
[]
struct
{
query
url
.
Values
...
...
@@ -118,7 +83,7 @@ func TestHandleAuthFuncResponsesSingleRedirectURL(t *testing.T) {
{
query
:
url
.
Values
{
"response_type"
:
[]
string
{
"code"
},
"client_id"
:
[]
string
{
"client.example.com"
},
"client_id"
:
[]
string
{
testClientID
},
"connector_id"
:
[]
string
{
"fake"
},
"scope"
:
[]
string
{
"openid"
},
},
...
...
@@ -210,7 +175,12 @@ func TestHandleAuthFuncResponsesSingleRedirectURL(t *testing.T) {
}
for
i
,
tt
:=
range
tests
{
hdlr
:=
handleAuthFunc
(
srv
,
idpcs
,
nil
,
true
)
f
,
err
:=
makeTestFixtures
()
if
err
!=
nil
{
t
.
Fatalf
(
"error making test fixtures: %v"
,
err
)
}
hdlr
:=
handleAuthFunc
(
f
.
srv
,
idpcs
,
nil
,
true
)
w
:=
httptest
.
NewRecorder
()
u
:=
fmt
.
Sprintf
(
"http://server.example.com?%s"
,
tt
.
query
.
Encode
())
req
,
err
:=
http
.
NewRequest
(
"GET"
,
u
,
nil
)
...
...
@@ -237,7 +207,6 @@ func TestHandleAuthFuncResponsesMultipleRedirectURLs(t *testing.T) {
&
fakeConnector
{
loginURL
:
"http://fake.example.com"
},
}
dbm
:=
db
.
NewMemDB
()
clients
:=
[]
client
.
Client
{
client
.
Client
{
Credentials
:
oidc
.
ClientCredentials
{
...
...
@@ -252,23 +221,11 @@ func TestHandleAuthFuncResponsesMultipleRedirectURLs(t *testing.T) {
},
},
}
clientIDGenerator
:=
func
(
hostport
string
)
(
string
,
error
)
{
return
hostport
,
nil
}
secGen
:=
func
()
([]
byte
,
error
)
{
return
[]
byte
(
"secret"
),
nil
}
clientRepo
:=
db
.
NewClientRepo
(
dbm
)
clientManager
,
err
:=
clientmanager
.
NewClientManagerFromClients
(
clientRepo
,
db
.
TransactionFactory
(
dbm
),
clients
,
clientmanager
.
ManagerOptions
{
ClientIDGenerator
:
clientIDGenerator
,
SecretGenerator
:
secGen
})
f
,
err
:=
makeTestFixturesWithOptions
(
testFixtureOptions
{
clients
:
clients
,
})
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to create client identity manager: %v"
,
err
)
}
srv
:=
&
Server
{
IssuerURL
:
url
.
URL
{
Scheme
:
"http"
,
Host
:
"server.example.com"
},
SessionManager
:
manager
.
NewSessionManager
(
db
.
NewSessionRepo
(
db
.
NewMemDB
()),
db
.
NewSessionKeyRepo
(
db
.
NewMemDB
())),
ClientRepo
:
clientRepo
,
ClientManager
:
clientManager
,
t
.
Fatalf
(
"error making test fixtures: %v"
,
err
)
}
tests
:=
[]
struct
{
...
...
@@ -327,7 +284,7 @@ func TestHandleAuthFuncResponsesMultipleRedirectURLs(t *testing.T) {
}
for
i
,
tt
:=
range
tests
{
hdlr
:=
handleAuthFunc
(
srv
,
idpcs
,
nil
,
true
)
hdlr
:=
handleAuthFunc
(
f
.
srv
,
idpcs
,
nil
,
true
)
w
:=
httptest
.
NewRecorder
()
u
:=
fmt
.
Sprintf
(
"http://server.example.com?%s"
,
tt
.
query
.
Encode
())
req
,
err
:=
http
.
NewRequest
(
"GET"
,
u
,
nil
)
...
...
server/testutil.go
View file @
a33d61c8
...
...
@@ -95,6 +95,10 @@ type testFixtures struct {
clientManager
*
clientmanager
.
ClientManager
}
type
testFixtureOptions
struct
{
clients
[]
client
.
Client
}
func
sequentialGenerateCodeFunc
()
sessionmanager
.
GenerateCodeFunc
{
x
:=
0
return
func
()
(
string
,
error
)
{
...
...
@@ -104,6 +108,10 @@ func sequentialGenerateCodeFunc() sessionmanager.GenerateCodeFunc {
}
func
makeTestFixtures
()
(
*
testFixtures
,
error
)
{
return
makeTestFixturesWithOptions
(
testFixtureOptions
{})
}
func
makeTestFixturesWithOptions
(
options
testFixtureOptions
)
(
*
testFixtures
,
error
)
{
dbMap
:=
db
.
NewMemDB
()
userRepo
,
err
:=
db
.
NewUserRepoFromUsers
(
dbMap
,
testUsers
)
if
err
!=
nil
{
...
...
@@ -150,15 +158,20 @@ func makeTestFixtures() (*testFixtures, error) {
return
nil
,
err
}
clients
:=
[]
client
.
Client
{
client
.
Client
{
Credentials
:
testClientCredentials
,
Metadata
:
oidc
.
ClientMetadata
{
RedirectURIs
:
[]
url
.
URL
{
testRedirectURL
,
var
clients
[]
client
.
Client
if
options
.
clients
==
nil
{
clients
=
[]
client
.
Client
{
client
.
Client
{
Credentials
:
testClientCredentials
,
Metadata
:
oidc
.
ClientMetadata
{
RedirectURIs
:
[]
url
.
URL
{
testRedirectURL
,
},
},
},
},
}
}
else
{
clients
=
options
.
clients
}
clientIDGenerator
:=
func
(
hostport
string
)
(
string
,
error
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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