1
0
Fork 0
mirror of https://github.com/Luzifer/nginx-sso.git synced 2024-12-20 21:01:17 +00:00
nginx-sso/vendor/github.com/jda/go-crowd/sso_test.go
Knut Ahlers 6fa934880e
Implement Crowd authentication (#2)
* Re-add example configuration for Crowd
* Implement Crowd authentication
* Fix: Some errors just mean there is no user
* Document crowd provider
* Vendor new dependencies
* Reduce error messages: Check for config details
2018-02-04 14:51:08 +01:00

75 lines
1.7 KiB
Go

package crowd
import (
"os"
"testing"
)
func TestSSOLifeCycle(t *testing.T) {
tv := PrepVars(t)
c, err := New(tv.AppUsername, tv.AppPassword, tv.AppURL)
if err != nil {
t.Error(err)
}
user := os.Getenv("APP_USER_USERNAME")
if user == "" {
t.Skip("Can't run test because APP_USER_USERNAME undefined")
}
passwd := os.Getenv("APP_USER_PASSWORD")
if passwd == "" {
t.Skip("Can't run test because APP_USER_PASSWORD undefined")
}
addr := "10.10.10.10"
// test new session
a, err := c.NewSession(user, passwd, addr)
if err != nil {
t.Errorf("Error creating new session: %s\n", err)
} else {
t.Logf("Got new session: %+v\n", a)
}
if a.Token == "" {
t.Errorf("Token was empty so we didn't get/decode a response from NewSession")
}
// test validate for session we just created
si, err := c.ValidateSession(a.Token, addr)
if err != nil {
t.Errorf("Error validating session: %s\n", err)
} else {
t.Logf("Validated session: %+v\n", si)
}
if si.Token == "" {
t.Errorf("Token was empty so we didn't get/decode a response from ValidateSession")
}
// test get info for session
sdat, err := c.GetSession(a.Token)
if err != nil {
t.Errorf("Error getting session: %s\n", err)
} else {
t.Logf("Got session: %+v\n", sdat)
}
// test invalidating session
err = c.InvalidateSession(a.Token)
if err != nil {
t.Errorf("Error invalidating session: %s\n", err)
} else {
t.Log("Invalidated session")
}
// make sure sesssion is gone
ivsess, err := c.ValidateSession(a.Token, addr)
if err == nil {
t.Errorf("Validating non-existant session should fail, got: %+v\n", ivsess)
} else {
t.Log("Could not validate session that doesn't exist (this is good)")
}
}