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
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
34 deletions
+63
-34
api_test.go
admin/api_test.go
+62
-33
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
package
admin
import
(
import
(
"net/http"
"testing"
"testing"
"github.com/coreos/dex/connector"
"github.com/coreos/dex/repo"
"github.com/coreos/dex/schema/adminschema"
"github.com/coreos/dex/schema/adminschema"
"github.com/coreos/dex/user"
"github.com/coreos/dex/user"
"github.com/coreos/dex/user/manager"
"github.com/kylelemons/godebug/pretty"
"github.com/kylelemons/godebug/pretty"
)
)
...
@@ -16,6 +15,7 @@ import (
...
@@ -16,6 +15,7 @@ import (
type
testFixtures
struct
{
type
testFixtures
struct
{
ur
user
.
UserRepo
ur
user
.
UserRepo
pwr
user
.
PasswordInfoRepo
pwr
user
.
PasswordInfoRepo
mgr
*
manager
.
UserManager
adAPI
*
AdminAPI
adAPI
*
AdminAPI
}
}
...
@@ -26,7 +26,15 @@ func makeTestFixtures() *testFixtures {
...
@@ -26,7 +26,15 @@ func makeTestFixtures() *testFixtures {
{
{
User
:
user
.
User
{
User
:
user
.
User
{
ID
:
"ID-1"
,
ID
:
"ID-1"
,
Name
:
"Name-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 {
...
@@ -36,8 +44,11 @@ func makeTestFixtures() *testFixtures {
Password
:
[]
byte
(
"hi."
),
Password
:
[]
byte
(
"hi."
),
},
},
})
})
ccr
:=
connector
.
NewConnectorConfigRepoFromConfigs
([]
connector
.
ConnectorConfig
{
f
.
adAPI
=
NewAdminAPI
(
f
.
ur
,
f
.
pwr
)
&
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
return
f
}
}
...
@@ -45,15 +56,15 @@ func makeTestFixtures() *testFixtures {
...
@@ -45,15 +56,15 @@ func makeTestFixtures() *testFixtures {
func
TestGetAdmin
(
t
*
testing
.
T
)
{
func
TestGetAdmin
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
tests
:=
[]
struct
{
id
string
id
string
errCode
int
wantErr
error
}{
}{
{
{
id
:
"ID-1"
,
id
:
"ID-1"
,
errCode
:
-
1
,
},
},
{
{
id
:
"ID-2"
,
// Not found
errCode
:
http
.
StatusNotFound
,
id
:
"ID-3"
,
wantErr
:
user
.
ErrorNotFound
,
},
},
}
}
...
@@ -61,7 +72,7 @@ func TestGetAdmin(t *testing.T) {
...
@@ -61,7 +72,7 @@ func TestGetAdmin(t *testing.T) {
f
:=
makeTestFixtures
()
f
:=
makeTestFixtures
()
admn
,
err
:=
f
.
adAPI
.
GetAdmin
(
tt
.
id
)
admn
,
err
:=
f
.
adAPI
.
GetAdmin
(
tt
.
id
)
if
tt
.
errCode
!=
-
1
{
if
tt
.
wantErr
!=
nil
{
if
err
==
nil
{
if
err
==
nil
{
t
.
Errorf
(
"case %d: err was nil"
,
i
)
t
.
Errorf
(
"case %d: err was nil"
,
i
)
continue
continue
...
@@ -72,15 +83,15 @@ func TestGetAdmin(t *testing.T) {
...
@@ -72,15 +83,15 @@ func TestGetAdmin(t *testing.T) {
continue
continue
}
}
if
aErr
.
Code
!=
tt
.
errCode
{
if
aErr
.
Internal
!=
tt
.
wantErr
{
t
.
Errorf
(
"case %d: want=%
d, got=%d"
,
i
,
tt
.
errCode
,
aErr
.
Code
)
t
.
Errorf
(
"case %d: want=%
q, got=%q"
,
i
,
tt
.
wantErr
,
aErr
.
Internal
)
continue
continue
}
}
}
else
{
}
else
{
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"case %d: err != nil: %q"
,
i
,
err
)
t
.
Errorf
(
"case %d: err != nil: %q"
,
i
,
err
)
}
continue
continue
}
if
admn
.
Id
!=
"ID-1"
{
if
admn
.
Id
!=
"ID-1"
{
t
.
Errorf
(
"case %d: want=%q, got=%q"
,
i
,
tt
.
id
,
admn
.
Id
)
t
.
Errorf
(
"case %d: want=%q, got=%q"
,
i
,
tt
.
id
,
admn
.
Id
)
...
@@ -92,38 +103,54 @@ func TestGetAdmin(t *testing.T) {
...
@@ -92,38 +103,54 @@ func TestGetAdmin(t *testing.T) {
}
}
func
TestCreateAdmin
(
t
*
testing
.
T
)
{
func
TestCreateAdmin
(
t
*
testing
.
T
)
{
hashedPassword
,
_
:=
user
.
NewPasswordFromPlaintext
(
"foopass"
)
tests
:=
[]
struct
{
tests
:=
[]
struct
{
admn
adminschema
.
Admin
admn
adminschema
.
Admin
errCode
int
wantErr
error
}{
}{
{
{
//hashed password
admn
:
adminschema
.
Admin
{
admn
:
adminschema
.
Admin
{
Name
:
"foo
"
,
Email
:
"goodemail@example.com
"
,
Password
Hash
:
user
.
Password
([]
byte
(
"foopass"
))
.
EncodeBase64
(
),
Password
:
string
(
hashedPassword
),
},
},
errCode
:
-
1
,
},
},
{
{
//
duplicate Name
//
plaintext password
admn
:
adminschema
.
Admin
{
admn
:
adminschema
.
Admin
{
Name
:
"Name-1
"
,
Email
:
"goodemail@example.com
"
,
Password
Hash
:
user
.
Password
([]
byte
(
"foopass"
))
.
EncodeBase64
()
,
Password
:
"foopass"
,
},
},
errCode
:
http
.
StatusBadRequest
,
},
},
{
{
//
missing Name
//
duplicate Email
admn
:
adminschema
.
Admin
{
admn
:
adminschema
.
Admin
{
PasswordHash
:
user
.
Password
([]
byte
(
"foopass"
))
.
EncodeBase64
(),
Email
:
"email-2@example.com"
,
Password
:
"foopass"
,
},
},
errCode
:
http
.
StatusBadRequest
,
wantErr
:
user
.
ErrorDuplicateEmail
,
},
{
// bad email
admn
:
adminschema
.
Admin
{
Email
:
"badEmailexample"
,
Password
:
"foopass"
,
},
wantErr
:
user
.
ErrorInvalidEmail
,
},
{
// missing Email
admn
:
adminschema
.
Admin
{
Password
:
"foopass"
,
},
wantErr
:
user
.
ErrorInvalidEmail
,
},
},
}
}
for
i
,
tt
:=
range
tests
{
for
i
,
tt
:=
range
tests
{
f
:=
makeTestFixtures
()
f
:=
makeTestFixtures
()
id
,
err
:=
f
.
adAPI
.
CreateAdmin
(
tt
.
admn
)
id
,
err
:=
f
.
adAPI
.
CreateAdmin
(
tt
.
admn
)
if
tt
.
errCode
!=
-
1
{
if
tt
.
wantErr
!=
nil
{
if
err
==
nil
{
if
err
==
nil
{
t
.
Errorf
(
"case %d: err was nil"
,
i
)
t
.
Errorf
(
"case %d: err was nil"
,
i
)
continue
continue
...
@@ -134,8 +161,8 @@ func TestCreateAdmin(t *testing.T) {
...
@@ -134,8 +161,8 @@ func TestCreateAdmin(t *testing.T) {
continue
continue
}
}
if
aErr
.
Code
!=
tt
.
errCode
{
if
aErr
.
Internal
!=
tt
.
wantErr
{
t
.
Errorf
(
"case %d: want=%
d, got=%d"
,
i
,
tt
.
errCode
,
aErr
.
Code
)
t
.
Errorf
(
"case %d: want=%
q, got=%q"
,
i
,
tt
.
wantErr
,
aErr
.
Internal
)
continue
continue
}
}
}
else
{
}
else
{
...
@@ -164,7 +191,9 @@ func TestGetState(t *testing.T) {
...
@@ -164,7 +191,9 @@ func TestGetState(t *testing.T) {
{
{
addUsers
:
[]
user
.
User
{
addUsers
:
[]
user
.
User
{
user
.
User
{
user
.
User
{
Name
:
"Admin"
,
ID
:
"ID-3"
,
Email
:
"email-3@example.com"
,
DisplayName
:
"Admin"
,
Admin
:
true
,
Admin
:
true
,
},
},
},
},
...
@@ -181,15 +210,15 @@ func TestGetState(t *testing.T) {
...
@@ -181,15 +210,15 @@ func TestGetState(t *testing.T) {
for
i
,
tt
:=
range
tests
{
for
i
,
tt
:=
range
tests
{
f
:=
makeTestFixtures
()
f
:=
makeTestFixtures
()
for
_
,
usr
:=
range
tt
.
addUsers
{
for
_
,
usr
:=
range
tt
.
addUsers
{
_
,
err
:=
f
.
ur
.
Create
(
usr
)
_
,
err
:=
f
.
mgr
.
CreateUser
(
usr
,
user
.
Password
(
"foopass"
),
f
.
adAPI
.
localConnectorID
)
if
err
!=
nil
{
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
()
got
,
err
:=
f
.
adAPI
.
GetState
()
if
err
!=
nil
{
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
!=
""
{
if
diff
:=
pretty
.
Compare
(
tt
.
want
,
got
);
diff
!=
""
{
...
...
test
View file @
5961122c
...
@@ -14,7 +14,7 @@ COVER=${COVER:-"-cover"}
...
@@ -14,7 +14,7 @@ COVER=${COVER:-"-cover"}
source
./build
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"
FORMATTABLE
=
"
$TESTABLE
cmd/dexctl cmd/dex-worker cmd/dex-overlord examples/app functional pkg/log"
# user has not provided PKG override
# 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