enhanced testcoverage of httpupstream

This commit is contained in:
Sebastian Mancke
2017-06-09 22:24:21 +02:00
parent c6291ca7e9
commit 7ceb900c37
3 changed files with 34 additions and 5 deletions
+4 -4
View File
@@ -195,7 +195,7 @@ Parameters for the provider:
Example:
```
loginsrv -backend 'provider=htpasswd,file=users
loginsrv -htpasswd file=users
```
### Httpupstream
@@ -210,7 +210,7 @@ Parameters for the provider:
Example:
```
loginsrv -backend 'provider=httpupstream,upstream=https://google.com,timeout=1s'
loginsrv -httpupstream upstream=https://google.com,timeout=1s
```
### OSIAM
@@ -219,7 +219,7 @@ It implements the multiple OAuth2 flows, as well as SCIM for managing the user d
To start loginsrv against the default OSIAM configuration on the same machine, use the following example.
```
loginsrv --jwt-secret=jwtsecret --text-logging -backend 'provider=osiam,endpoint=http://localhost:8080,clientId=example-client,clientSecret=secret'
loginsrv --jwt-secret=jwtsecret --text-logging -osiam endpoint=http://localhost:8080,client_id=example-client,client_secret=secret'
```
Then go to http://127.0.0.1:6789/login and login with `admin/koala`.
@@ -229,7 +229,7 @@ Simple is a demo provider for testing only. It holds a user/password table in me
Example
```
loginsrv -backend provider=simple,bob=secret
loginsrv -simple bob=secret
```
## Oauth2
+21 -1
View File
@@ -44,5 +44,25 @@ func TestAuth_ValidCredentials(t *testing.T) {
authenticated, err := auth.Authenticate("bob-bcrypt", "secret")
NoError(t, err)
False(t, authenticated)
True(t, authenticated)
}
func TestAuth_InvalidUrl(t *testing.T) {
invalidUrl := &url.URL{Scheme: "\\\\"}
auth, err := NewAuth(invalidUrl, time.Second, false)
NoError(t, err)
_, err = auth.Authenticate("foo", "bar")
Error(t, err)
}
func TestAuth_InvalidHost(t *testing.T) {
invalidServer, _ := url.Parse("http://0.0.0.0.0")
auth, err := NewAuth(invalidServer, time.Second, false)
NoError(t, err)
_, err = auth.Authenticate("foo", "bar")
Error(t, err)
}
+9
View File
@@ -62,6 +62,15 @@ func TestSetup_Error(t *testing.T) {
_, err := p(map[string]string{})
Error(t, err)
_, err = p(map[string]string{"upstream": ":invalid-url"})
Error(t, err)
_, err = p(map[string]string{"upstream": "http://example.com", "timeout": "some-string"})
Error(t, err)
_, err = p(map[string]string{"upstream": "http://example.com", "skipverify": "some-string"})
Error(t, err)
}
func TestSimpleBackend_Authenticate(t *testing.T) {