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
158bfa5e
Commit
158bfa5e
authored
Apr 15, 2016
by
Bobby Rullo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
client: Add tests for ClientsFromReader
Also require client ID and secret.
parent
e5948ab3
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
155 additions
and
0 deletions
+155
-0
client.go
client/client.go
+6
-0
client_test.go
client/client_test.go
+149
-0
No files found.
client/client.go
View file @
158bfa5e
...
...
@@ -86,6 +86,12 @@ func ClientsFromReader(r io.Reader) ([]Client, error) {
}
clients
:=
make
([]
Client
,
len
(
c
))
for
i
,
client
:=
range
c
{
if
client
.
ID
==
""
{
return
nil
,
errors
.
New
(
"clients must have an ID"
)
}
if
len
(
client
.
Secret
)
==
0
{
return
nil
,
errors
.
New
(
"clients must have a Secret"
)
}
redirectURIs
:=
make
([]
url
.
URL
,
len
(
client
.
RedirectURLs
))
for
j
,
u
:=
range
client
.
RedirectURLs
{
uri
,
err
:=
url
.
Parse
(
u
)
...
...
client/client_test.go
0 → 100644
View file @
158bfa5e
package
client
import
(
"encoding/base64"
"net/url"
"strings"
"testing"
"github.com/coreos/go-oidc/oidc"
"github.com/kylelemons/godebug/pretty"
)
var
(
goodSecret1
=
base64
.
URLEncoding
.
EncodeToString
([]
byte
(
"my_secret"
))
goodSecret2
=
base64
.
URLEncoding
.
EncodeToString
([]
byte
(
"my_other_secret"
))
goodClient1
=
`{
"id": "my_id",
"secret": "`
+
goodSecret1
+
`",
"redirectURLs": ["https://client.example.com"]
}`
goodClient2
=
`{
"id": "my_other_id",
"secret": "`
+
goodSecret2
+
`",
"redirectURLs": ["https://client2.example.com","https://client2_a.example.com"]
}`
badURLClient
=
`{
"id": "my_id",
"secret": "`
+
goodSecret1
+
`",
"redirectURLs": ["hdtp:/\(bad)(u)(r)(l)"]
}`
badSecretClient
=
`{
"id": "my_id",
"secret": "`
+
"****"
+
`",
"redirectURLs": ["https://client.example.com"]
}`
noSecretClient
=
`{
"id": "my_id",
"redirectURLs": ["https://client.example.com"]
}`
noIDClient
=
`{
"secret": "`
+
goodSecret1
+
`",
"redirectURLs": ["https://client.example.com"]
}`
)
func
TestClientsFromReader
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
json
string
want
[]
Client
wantErr
bool
}{
{
json
:
"[]"
,
want
:
[]
Client
{},
},
{
json
:
"["
+
goodClient1
+
"]"
,
want
:
[]
Client
{
{
Credentials
:
oidc
.
ClientCredentials
{
ID
:
"my_id"
,
Secret
:
"my_secret"
,
},
Metadata
:
oidc
.
ClientMetadata
{
RedirectURIs
:
[]
url
.
URL
{
mustParseURL
(
t
,
"https://client.example.com"
),
},
},
},
},
},
{
json
:
"["
+
strings
.
Join
([]
string
{
goodClient1
,
goodClient2
},
","
)
+
"]"
,
want
:
[]
Client
{
{
Credentials
:
oidc
.
ClientCredentials
{
ID
:
"my_id"
,
Secret
:
"my_secret"
,
},
Metadata
:
oidc
.
ClientMetadata
{
RedirectURIs
:
[]
url
.
URL
{
mustParseURL
(
t
,
"https://client.example.com"
),
},
},
},
{
Credentials
:
oidc
.
ClientCredentials
{
ID
:
"my_other_id"
,
Secret
:
"my_other_secret"
,
},
Metadata
:
oidc
.
ClientMetadata
{
RedirectURIs
:
[]
url
.
URL
{
mustParseURL
(
t
,
"https://client2.example.com"
),
mustParseURL
(
t
,
"https://client2_a.example.com"
),
},
},
},
},
},
{
json
:
"["
+
badURLClient
+
"]"
,
wantErr
:
true
,
},
{
json
:
"["
+
badSecretClient
+
"]"
,
wantErr
:
true
,
},
{
json
:
"["
+
noSecretClient
+
"]"
,
wantErr
:
true
,
},
{
json
:
"["
+
noIDClient
+
"]"
,
wantErr
:
true
,
},
}
for
i
,
tt
:=
range
tests
{
r
:=
strings
.
NewReader
(
tt
.
json
)
cs
,
err
:=
ClientsFromReader
(
r
)
if
tt
.
wantErr
{
if
err
==
nil
{
t
.
Errorf
(
"case %d: want non-nil err"
,
i
)
t
.
Logf
(
pretty
.
Sprint
(
cs
))
}
continue
}
if
err
!=
nil
{
t
.
Errorf
(
"case %d: got unexpected error parsing clients: %v"
,
i
,
err
)
t
.
Logf
(
tt
.
json
)
}
if
diff
:=
pretty
.
Compare
(
tt
.
want
,
cs
);
diff
!=
""
{
t
.
Errorf
(
"case %d: Compare(want, got): %v"
,
i
,
diff
)
}
}
}
func
mustParseURL
(
t
*
testing
.
T
,
s
string
)
url
.
URL
{
u
,
err
:=
url
.
Parse
(
s
)
if
err
!=
nil
{
t
.
Fatalf
(
"Cannot parse %v as url: %v"
,
s
,
err
)
}
return
*
u
}
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