mirror of
https://github.com/pomerium/pomerium.git
synced 2025-07-21 10:38:08 +02:00
Signed-off-by: Bobby DeSimone <bobbydesimone@gmail.com> Co-authored-by: bobby <1544881+desimone@users.noreply.github.com>
This commit is contained in:
parent
e86989e248
commit
4e1c99c897
4 changed files with 47 additions and 23 deletions
|
@ -1,6 +1,7 @@
|
|||
package authorize
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -13,31 +14,49 @@ func TestNew(t *testing.T) {
|
|||
t.Parallel()
|
||||
policies := testPolicies(t)
|
||||
tests := []struct {
|
||||
name string
|
||||
SharedKey string
|
||||
Policies []config.Policy
|
||||
wantErr bool
|
||||
name string
|
||||
config config.Options
|
||||
wantErr bool
|
||||
}{
|
||||
{"good", "gXK6ggrlIW2HyKyUF9rUO4azrDgxhDPWqw9y+lJU7B8=", policies, false},
|
||||
{"bad shared secret", "AZA85podM73CjLCjViDNz1EUvvejKpWp7Hysr0knXA==", policies, true},
|
||||
{"really bad shared secret", "sup", policies, true},
|
||||
{"validation error, short secret", "AZA85podM73CjLCjViDNz1EUvvejKpWp7Hysr0knXA==", policies, true},
|
||||
{"empty options", "", []config.Policy{}, true}, // special case
|
||||
|
||||
{"good",
|
||||
config.Options{
|
||||
AuthenticateURL: mustParseURL("https://authN.example.com"),
|
||||
DataBrokerURL: mustParseURL("https://cache.example.com"),
|
||||
SharedKey: "2p/Wi2Q6bYDfzmoSEbKqYKtg+DUoLWTEHHs7vOhvL7w=",
|
||||
Policies: policies},
|
||||
false},
|
||||
{"bad shared secret",
|
||||
config.Options{
|
||||
AuthenticateURL: mustParseURL("https://authN.example.com"),
|
||||
DataBrokerURL: mustParseURL("https://cache.example.com"),
|
||||
SharedKey: "AZA85podM73CjLCjViDNz1EUvvejKpWp7Hysr0knXA==",
|
||||
Policies: policies}, true},
|
||||
{"really bad shared secret",
|
||||
config.Options{
|
||||
AuthenticateURL: mustParseURL("https://authN.example.com"),
|
||||
DataBrokerURL: mustParseURL("https://cache.example.com"),
|
||||
SharedKey: "sup",
|
||||
Policies: policies}, true},
|
||||
{"validation error, short secret",
|
||||
config.Options{
|
||||
AuthenticateURL: mustParseURL("https://authN.example.com"),
|
||||
DataBrokerURL: mustParseURL("https://cache.example.com"),
|
||||
SharedKey: "AZA85podM73CjLCjViDNz1EUvvejKpWp7Hysr0knXA==",
|
||||
Policies: policies}, true},
|
||||
{"empty options", config.Options{}, true},
|
||||
{"bad cache url",
|
||||
config.Options{
|
||||
AuthenticateURL: mustParseURL("https://authN.example.com"),
|
||||
DataBrokerURL: &url.URL{},
|
||||
SharedKey: "AZA85podM73CjLCjViDNz1EUvvejKpWp7Hysr0knXA==",
|
||||
Policies: policies},
|
||||
true},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
o := &config.Options{
|
||||
AuthenticateURL: mustParseURL("https://authN.example.com"),
|
||||
DataBrokerURL: mustParseURL("https://cache.example.com"),
|
||||
SharedKey: tt.SharedKey,
|
||||
Policies: tt.Policies}
|
||||
if tt.name == "empty options" {
|
||||
o = &config.Options{}
|
||||
}
|
||||
_, err := New(o)
|
||||
_, err := New(&tt.config)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("New() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue