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
5961122c
Commit
5961122c
authored
Jan 28, 2016
by
Eric Chiang
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #291 from Tecsisa/admintest
admin: tests do not compile (Fixes #257)
parents
c7606ae3
4c7fc432
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
37 deletions
+66
-37
api_test.go
admin/api_test.go
+65
-36
test
test
+1
-1
No files found.
admin/api_test.go
View file @
5961122c
// NOTE: These tests are begin updated so they compile (see #257). Until then ignore.
// +build ignore
package
admin
import
(
"net/http"
"testing"
"github.com/coreos/dex/connector"
"github.com/coreos/dex/repo"
"github.com/coreos/dex/schema/adminschema"
"github.com/coreos/dex/user"
"github.com/coreos/dex/user/manager"
"github.com/kylelemons/godebug/pretty"
)
...
...
@@ -16,6 +15,7 @@ import (
type
testFixtures
struct
{
ur
user
.
UserRepo
pwr
user
.
PasswordInfoRepo
mgr
*
manager
.
UserManager
adAPI
*
AdminAPI
}
...
...
@@ -25,8 +25,16 @@ func makeTestFixtures() *testFixtures {
f
.
ur
=
user
.
NewUserRepoFromUsers
([]
user
.
UserWithRemoteIdentities
{
{
User
:
user
.
User
{
ID
:
"ID-1"
,
Name
:
"Name-1"
,
ID
:
"ID-1"
,
Email
:
"email-1@example.com"
,
DisplayName
:
"Name-1"
,
},
},
{
User
:
user
.
User
{
ID
:
"ID-2"
,
Email
:
"email-2@example.com"
,
DisplayName
:
"Name-2"
,
},
},
})
...
...
@@ -36,8 +44,11 @@ func makeTestFixtures() *testFixtures {
Password
:
[]
byte
(
"hi."
),
},
})
f
.
adAPI
=
NewAdminAPI
(
f
.
ur
,
f
.
pwr
)
ccr
:=
connector
.
NewConnectorConfigRepoFromConfigs
([]
connector
.
ConnectorConfig
{
&
connector
.
LocalConnectorConfig
{
ID
:
"local"
},
})
f
.
mgr
=
manager
.
NewUserManager
(
f
.
ur
,
f
.
pwr
,
ccr
,
repo
.
InMemTransactionFactory
,
manager
.
ManagerOptions
{})
f
.
adAPI
=
NewAdminAPI
(
f
.
mgr
,
f
.
ur
,
f
.
pwr
,
"local"
)
return
f
}
...
...
@@ -45,15 +56,15 @@ func makeTestFixtures() *testFixtures {
func
TestGetAdmin
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
id
string
errCode
int
wantErr
error
}{
{
id
:
"ID-1"
,
errCode
:
-
1
,
id
:
"ID-1"
,
},
{
id
:
"ID-2"
,
errCode
:
http
.
StatusNotFound
,
// Not found
id
:
"ID-3"
,
wantErr
:
user
.
ErrorNotFound
,
},
}
...
...
@@ -61,7 +72,7 @@ func TestGetAdmin(t *testing.T) {
f
:=
makeTestFixtures
()
admn
,
err
:=
f
.
adAPI
.
GetAdmin
(
tt
.
id
)
if
tt
.
errCode
!=
-
1
{
if
tt
.
wantErr
!=
nil
{
if
err
==
nil
{
t
.
Errorf
(
"case %d: err was nil"
,
i
)
continue
...
...
@@ -72,15 +83,15 @@ func TestGetAdmin(t *testing.T) {
continue
}
if
aErr
.
Code
!=
tt
.
errCode
{
t
.
Errorf
(
"case %d: want=%
d, got=%d"
,
i
,
tt
.
errCode
,
aErr
.
Code
)
if
aErr
.
Internal
!=
tt
.
wantErr
{
t
.
Errorf
(
"case %d: want=%
q, got=%q"
,
i
,
tt
.
wantErr
,
aErr
.
Internal
)
continue
}
}
else
{
if
err
!=
nil
{
t
.
Errorf
(
"case %d: err != nil: %q"
,
i
,
err
)
continue
}
continue
if
admn
.
Id
!=
"ID-1"
{
t
.
Errorf
(
"case %d: want=%q, got=%q"
,
i
,
tt
.
id
,
admn
.
Id
)
...
...
@@ -92,38 +103,54 @@ func TestGetAdmin(t *testing.T) {
}
func
TestCreateAdmin
(
t
*
testing
.
T
)
{
hashedPassword
,
_
:=
user
.
NewPasswordFromPlaintext
(
"foopass"
)
tests
:=
[]
struct
{
admn
adminschema
.
Admin
errCode
int
wantErr
error
}{
{
//hashed password
admn
:
adminschema
.
Admin
{
Email
:
"goodemail@example.com"
,
Password
:
string
(
hashedPassword
),
},
},
{
//plaintext password
admn
:
adminschema
.
Admin
{
Email
:
"goodemail@example.com"
,
Password
:
"foopass"
,
},
},
{
// duplicate Email
admn
:
adminschema
.
Admin
{
Name
:
"foo
"
,
Password
Hash
:
user
.
Password
([]
byte
(
"foopass"
))
.
EncodeBase64
()
,
Email
:
"email-2@example.com
"
,
Password
:
"foopass"
,
},
errCode
:
-
1
,
wantErr
:
user
.
ErrorDuplicateEmail
,
},
{
//
duplicate Name
//
bad email
admn
:
adminschema
.
Admin
{
Name
:
"Name-1
"
,
Password
Hash
:
user
.
Password
([]
byte
(
"foopass"
))
.
EncodeBase64
()
,
Email
:
"badEmailexample
"
,
Password
:
"foopass"
,
},
errCode
:
http
.
StatusBadRequest
,
wantErr
:
user
.
ErrorInvalidEmail
,
},
{
// missing
Name
// missing
Email
admn
:
adminschema
.
Admin
{
Password
Hash
:
user
.
Password
([]
byte
(
"foopass"
))
.
EncodeBase64
()
,
Password
:
"foopass"
,
},
errCode
:
http
.
StatusBadRequest
,
wantErr
:
user
.
ErrorInvalidEmail
,
},
}
for
i
,
tt
:=
range
tests
{
f
:=
makeTestFixtures
()
id
,
err
:=
f
.
adAPI
.
CreateAdmin
(
tt
.
admn
)
if
tt
.
errCode
!=
-
1
{
if
tt
.
wantErr
!=
nil
{
if
err
==
nil
{
t
.
Errorf
(
"case %d: err was nil"
,
i
)
continue
...
...
@@ -134,8 +161,8 @@ func TestCreateAdmin(t *testing.T) {
continue
}
if
aErr
.
Code
!=
tt
.
errCode
{
t
.
Errorf
(
"case %d: want=%
d, got=%d"
,
i
,
tt
.
errCode
,
aErr
.
Code
)
if
aErr
.
Internal
!=
tt
.
wantErr
{
t
.
Errorf
(
"case %d: want=%
q, got=%q"
,
i
,
tt
.
wantErr
,
aErr
.
Internal
)
continue
}
}
else
{
...
...
@@ -164,8 +191,10 @@ func TestGetState(t *testing.T) {
{
addUsers
:
[]
user
.
User
{
user
.
User
{
Name
:
"Admin"
,
Admin
:
true
,
ID
:
"ID-3"
,
Email
:
"email-3@example.com"
,
DisplayName
:
"Admin"
,
Admin
:
true
,
},
},
want
:
adminschema
.
State
{
...
...
@@ -181,15 +210,15 @@ func TestGetState(t *testing.T) {
for
i
,
tt
:=
range
tests
{
f
:=
makeTestFixtures
()
for
_
,
usr
:=
range
tt
.
addUsers
{
_
,
err
:=
f
.
ur
.
Create
(
usr
)
_
,
err
:=
f
.
mgr
.
CreateUser
(
usr
,
user
.
Password
(
"foopass"
),
f
.
adAPI
.
localConnectorID
)
if
err
!=
nil
{
t
.
Fatalf
(
"case %d: err != nil"
,
i
,
err
)
t
.
Fatalf
(
"case %d: err != nil
: %q
"
,
i
,
err
)
}
}
got
,
err
:=
f
.
adAPI
.
GetState
()
if
err
!=
nil
{
t
.
Errorf
(
"case %d: err != nil"
,
i
,
err
)
t
.
Errorf
(
"case %d: err != nil
: %q
"
,
i
,
err
)
}
if
diff
:=
pretty
.
Compare
(
tt
.
want
,
got
);
diff
!=
""
{
...
...
test
View file @
5961122c
...
...
@@ -14,7 +14,7 @@ COVER=${COVER:-"-cover"}
source
./build
TESTABLE
=
"connector db integration pkg/crypto pkg/flag pkg/http pkg/net pkg/time pkg/html functional/repo server session user user/api user/manager email"
TESTABLE
=
"connector db integration pkg/crypto pkg/flag pkg/http pkg/net pkg/time pkg/html functional/repo server session user user/api user/manager email
admin
"
FORMATTABLE
=
"
$TESTABLE
cmd/dexctl cmd/dex-worker cmd/dex-overlord examples/app functional pkg/log"
# user has not provided PKG override
...
...
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