2018-11-27 10:28:46 +00:00
|
|
|
package keystone
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2018-12-13 11:22:53 +00:00
|
|
|
"context"
|
2018-11-27 10:28:46 +00:00
|
|
|
"encoding/json"
|
2018-12-13 11:22:53 +00:00
|
|
|
"fmt"
|
2018-11-27 10:28:46 +00:00
|
|
|
"io/ioutil"
|
2018-12-13 11:22:53 +00:00
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
"reflect"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
2018-11-27 10:28:46 +00:00
|
|
|
|
2018-12-13 11:22:53 +00:00
|
|
|
"github.com/dexidp/dex/connector"
|
|
|
|
)
|
2018-11-27 10:28:46 +00:00
|
|
|
|
2018-12-13 11:22:53 +00:00
|
|
|
const (
|
|
|
|
invalidPass = "WRONG_PASS"
|
2018-11-27 10:28:46 +00:00
|
|
|
|
2018-12-13 11:22:53 +00:00
|
|
|
testUser = "test_user"
|
|
|
|
testPass = "test_pass"
|
|
|
|
testEmail = "test@example.com"
|
|
|
|
testGroup = "test_group"
|
|
|
|
testDomain = "default"
|
|
|
|
)
|
2018-11-27 10:28:46 +00:00
|
|
|
|
2018-12-13 11:22:53 +00:00
|
|
|
var (
|
|
|
|
keystoneURL = ""
|
|
|
|
keystoneAdminURL = ""
|
2018-12-20 16:25:22 +00:00
|
|
|
adminUser = ""
|
|
|
|
adminPass = ""
|
2018-12-13 11:22:53 +00:00
|
|
|
authTokenURL = ""
|
|
|
|
usersURL = ""
|
|
|
|
groupsURL = ""
|
|
|
|
)
|
2018-11-27 10:28:46 +00:00
|
|
|
|
2018-12-13 11:22:53 +00:00
|
|
|
type groupResponse struct {
|
|
|
|
Group struct {
|
|
|
|
ID string `json:"id"`
|
|
|
|
} `json:"group"`
|
2018-11-27 10:28:46 +00:00
|
|
|
}
|
|
|
|
|
2018-12-13 11:22:53 +00:00
|
|
|
func getAdminToken(t *testing.T, adminName, adminPass string) (token, id string) {
|
|
|
|
t.Helper()
|
2018-11-27 10:28:46 +00:00
|
|
|
client := &http.Client{}
|
|
|
|
|
2018-12-13 11:22:53 +00:00
|
|
|
jsonData := loginRequestData{
|
|
|
|
auth: auth{
|
|
|
|
Identity: identity{
|
|
|
|
Methods: []string{"password"},
|
|
|
|
Password: password{
|
|
|
|
User: user{
|
|
|
|
Name: adminName,
|
|
|
|
Domain: domain{ID: testDomain},
|
|
|
|
Password: adminPass,
|
2018-11-27 10:28:46 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-12-13 11:22:53 +00:00
|
|
|
body, err := json.Marshal(jsonData)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-11-27 10:28:46 +00:00
|
|
|
|
2018-12-13 11:22:53 +00:00
|
|
|
req, err := http.NewRequest("POST", authTokenURL, bytes.NewBuffer(body))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("keystone: failed to obtain admin token: %v\n", err)
|
|
|
|
}
|
2018-11-27 10:28:46 +00:00
|
|
|
|
|
|
|
req.Header.Set("Content-Type", "application/json")
|
2018-12-13 11:22:53 +00:00
|
|
|
resp, err := client.Do(req)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-11-27 10:28:46 +00:00
|
|
|
|
2018-12-13 11:22:53 +00:00
|
|
|
token = resp.Header.Get("X-Subject-Token")
|
|
|
|
|
|
|
|
data, err := ioutil.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
2020-11-03 19:50:09 +00:00
|
|
|
tokenResp := new(tokenResponse)
|
2018-12-13 11:22:53 +00:00
|
|
|
err = json.Unmarshal(data, &tokenResp)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
return token, tokenResp.Token.User.ID
|
2018-11-27 10:28:46 +00:00
|
|
|
}
|
|
|
|
|
2018-12-13 11:22:53 +00:00
|
|
|
func createUser(t *testing.T, token, userName, userEmail, userPass string) string {
|
|
|
|
t.Helper()
|
2018-11-27 10:28:46 +00:00
|
|
|
client := &http.Client{}
|
|
|
|
|
2018-12-13 11:22:53 +00:00
|
|
|
createUserData := map[string]interface{}{
|
|
|
|
"user": map[string]interface{}{
|
|
|
|
"name": userName,
|
|
|
|
"email": userEmail,
|
|
|
|
"enabled": true,
|
|
|
|
"password": userPass,
|
|
|
|
"roles": []string{"admin"},
|
2018-11-27 10:28:46 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-12-13 11:22:53 +00:00
|
|
|
body, err := json.Marshal(createUserData)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-11-27 10:28:46 +00:00
|
|
|
|
2018-12-13 11:22:53 +00:00
|
|
|
req, err := http.NewRequest("POST", usersURL, bytes.NewBuffer(body))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-11-27 10:28:46 +00:00
|
|
|
req.Header.Set("X-Auth-Token", token)
|
|
|
|
req.Header.Add("Content-Type", "application/json")
|
2018-12-13 11:22:53 +00:00
|
|
|
resp, err := client.Do(req)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-11-27 10:28:46 +00:00
|
|
|
|
2018-12-13 11:22:53 +00:00
|
|
|
data, err := ioutil.ReadAll(resp.Body)
|
2018-11-27 10:28:46 +00:00
|
|
|
if err != nil {
|
2018-12-13 11:22:53 +00:00
|
|
|
t.Fatal(err)
|
2018-11-27 10:28:46 +00:00
|
|
|
}
|
2018-12-13 11:22:53 +00:00
|
|
|
defer resp.Body.Close()
|
2018-11-27 10:28:46 +00:00
|
|
|
|
2020-11-03 19:50:09 +00:00
|
|
|
userResp := new(userResponse)
|
2018-12-13 11:22:53 +00:00
|
|
|
err = json.Unmarshal(data, &userResp)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-11-27 10:28:46 +00:00
|
|
|
|
2018-12-13 11:22:53 +00:00
|
|
|
return userResp.User.ID
|
2018-11-27 10:28:46 +00:00
|
|
|
}
|
|
|
|
|
2018-12-13 11:22:53 +00:00
|
|
|
// delete group or user
|
2020-04-06 13:40:17 +00:00
|
|
|
func deleteResource(t *testing.T, token, id, uri string) {
|
2018-12-13 11:22:53 +00:00
|
|
|
t.Helper()
|
2018-11-27 10:28:46 +00:00
|
|
|
client := &http.Client{}
|
|
|
|
|
2018-12-13 11:22:53 +00:00
|
|
|
deleteURI := uri + id
|
|
|
|
req, err := http.NewRequest("DELETE", deleteURI, nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error: %v", err)
|
|
|
|
}
|
2018-11-27 10:28:46 +00:00
|
|
|
req.Header.Set("X-Auth-Token", token)
|
2019-12-18 15:04:03 +00:00
|
|
|
|
|
|
|
resp, err := client.Do(req)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error: %v", err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
2018-11-27 10:28:46 +00:00
|
|
|
}
|
|
|
|
|
2018-12-13 11:22:53 +00:00
|
|
|
func createGroup(t *testing.T, token, description, name string) string {
|
|
|
|
t.Helper()
|
2018-11-27 10:28:46 +00:00
|
|
|
client := &http.Client{}
|
|
|
|
|
2018-12-13 11:22:53 +00:00
|
|
|
createGroupData := map[string]interface{}{
|
|
|
|
"group": map[string]interface{}{
|
|
|
|
"name": name,
|
|
|
|
"description": description,
|
2018-11-27 10:28:46 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-12-13 11:22:53 +00:00
|
|
|
body, err := json.Marshal(createGroupData)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-11-27 10:28:46 +00:00
|
|
|
|
2018-12-13 11:22:53 +00:00
|
|
|
req, err := http.NewRequest("POST", groupsURL, bytes.NewBuffer(body))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-11-27 10:28:46 +00:00
|
|
|
req.Header.Set("X-Auth-Token", token)
|
|
|
|
req.Header.Add("Content-Type", "application/json")
|
2018-12-13 11:22:53 +00:00
|
|
|
resp, err := client.Do(req)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
data, err := ioutil.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
2018-11-27 10:28:46 +00:00
|
|
|
|
2020-11-03 19:50:09 +00:00
|
|
|
groupResp := new(groupResponse)
|
2018-12-13 11:22:53 +00:00
|
|
|
err = json.Unmarshal(data, &groupResp)
|
2018-11-27 10:28:46 +00:00
|
|
|
if err != nil {
|
2018-12-13 11:22:53 +00:00
|
|
|
t.Fatal(err)
|
2018-11-27 10:28:46 +00:00
|
|
|
}
|
|
|
|
|
2018-12-13 11:22:53 +00:00
|
|
|
return groupResp.Group.ID
|
2018-11-27 10:28:46 +00:00
|
|
|
}
|
|
|
|
|
2018-12-13 11:22:53 +00:00
|
|
|
func addUserToGroup(t *testing.T, token, groupID, userID string) error {
|
|
|
|
t.Helper()
|
|
|
|
uri := groupsURL + groupID + "/users/" + userID
|
2018-11-27 10:28:46 +00:00
|
|
|
client := &http.Client{}
|
2018-12-13 11:22:53 +00:00
|
|
|
req, err := http.NewRequest("PUT", uri, nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-11-27 10:28:46 +00:00
|
|
|
req.Header.Set("X-Auth-Token", token)
|
2019-12-18 15:04:03 +00:00
|
|
|
|
|
|
|
resp, err := client.Do(req)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error: %v", err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
2018-12-13 11:22:53 +00:00
|
|
|
return nil
|
2018-11-27 10:28:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestIncorrectCredentialsLogin(t *testing.T) {
|
2018-12-20 16:25:22 +00:00
|
|
|
setupVariables(t)
|
2020-11-03 19:50:09 +00:00
|
|
|
c := conn{
|
|
|
|
Host: keystoneURL, Domain: testDomain,
|
|
|
|
AdminUsername: adminUser, AdminPassword: adminPass,
|
|
|
|
}
|
2018-12-13 11:22:53 +00:00
|
|
|
s := connector.Scopes{OfflineAccess: true, Groups: true}
|
|
|
|
_, validPW, err := c.Login(context.Background(), s, adminUser, invalidPass)
|
|
|
|
|
|
|
|
if validPW {
|
2018-12-20 16:25:22 +00:00
|
|
|
t.Fatal("Incorrect password check")
|
|
|
|
}
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("Error should be returned when invalid password is provided")
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(err.Error(), "401") {
|
|
|
|
t.Fatal("Unrecognized error, expecting 401")
|
2018-12-13 11:22:53 +00:00
|
|
|
}
|
2018-11-27 10:28:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestValidUserLogin(t *testing.T) {
|
2018-12-20 16:25:22 +00:00
|
|
|
setupVariables(t)
|
2018-12-13 11:22:53 +00:00
|
|
|
token, _ := getAdminToken(t, adminUser, adminPass)
|
2020-04-06 13:40:17 +00:00
|
|
|
|
|
|
|
type tUser struct {
|
|
|
|
username string
|
|
|
|
domain string
|
|
|
|
email string
|
|
|
|
password string
|
|
|
|
}
|
|
|
|
|
|
|
|
type expect struct {
|
|
|
|
username string
|
|
|
|
email string
|
|
|
|
verifiedEmail bool
|
|
|
|
}
|
|
|
|
|
2020-11-03 19:50:09 +00:00
|
|
|
tests := []struct {
|
2020-04-06 13:40:17 +00:00
|
|
|
name string
|
|
|
|
input tUser
|
|
|
|
expected expect
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "test with email address",
|
|
|
|
input: tUser{
|
|
|
|
username: testUser,
|
|
|
|
domain: testDomain,
|
|
|
|
email: testEmail,
|
|
|
|
password: testPass,
|
|
|
|
},
|
|
|
|
expected: expect{
|
|
|
|
username: testUser,
|
|
|
|
email: testEmail,
|
|
|
|
verifiedEmail: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "test without email address",
|
|
|
|
input: tUser{
|
|
|
|
username: testUser,
|
|
|
|
domain: testDomain,
|
|
|
|
email: "",
|
|
|
|
password: testPass,
|
|
|
|
},
|
|
|
|
expected: expect{
|
|
|
|
username: testUser,
|
|
|
|
email: "",
|
|
|
|
verifiedEmail: false,
|
|
|
|
},
|
|
|
|
},
|
2018-12-13 11:22:53 +00:00
|
|
|
}
|
|
|
|
|
2020-04-06 13:40:17 +00:00
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
userID := createUser(t, token, tt.input.username, tt.input.email, tt.input.password)
|
|
|
|
defer deleteResource(t, token, userID, usersURL)
|
|
|
|
|
2020-11-03 19:50:09 +00:00
|
|
|
c := conn{
|
|
|
|
Host: keystoneURL, Domain: tt.input.domain,
|
|
|
|
AdminUsername: adminUser, AdminPassword: adminPass,
|
|
|
|
}
|
2020-04-06 13:40:17 +00:00
|
|
|
s := connector.Scopes{OfflineAccess: true, Groups: true}
|
|
|
|
identity, validPW, err := c.Login(context.Background(), s, tt.input.username, tt.input.password)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err.Error())
|
|
|
|
}
|
|
|
|
t.Log(identity)
|
|
|
|
if identity.Username != tt.expected.username {
|
|
|
|
t.Fatalf("Invalid user. Got: %v. Wanted: %v", identity.Username, tt.expected.username)
|
|
|
|
}
|
|
|
|
if identity.UserID == "" {
|
|
|
|
t.Fatalf("Didn't get any UserID back")
|
|
|
|
}
|
|
|
|
if identity.Email != tt.expected.email {
|
|
|
|
t.Fatalf("Invalid email. Got: %v. Wanted: %v", identity.Email, tt.expected.email)
|
|
|
|
}
|
|
|
|
if identity.EmailVerified != tt.expected.verifiedEmail {
|
|
|
|
t.Fatalf("Invalid verifiedEmail. Got: %v. Wanted: %v", identity.EmailVerified, tt.expected.verifiedEmail)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !validPW {
|
|
|
|
t.Fatal("Valid password was not accepted")
|
|
|
|
}
|
|
|
|
})
|
2018-12-13 11:22:53 +00:00
|
|
|
}
|
2018-11-27 10:28:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestUseRefreshToken(t *testing.T) {
|
2018-12-20 16:25:22 +00:00
|
|
|
setupVariables(t)
|
2018-12-13 11:22:53 +00:00
|
|
|
token, adminID := getAdminToken(t, adminUser, adminPass)
|
|
|
|
groupID := createGroup(t, token, "Test group description", testGroup)
|
|
|
|
addUserToGroup(t, token, groupID, adminID)
|
2020-04-06 13:40:17 +00:00
|
|
|
defer deleteResource(t, token, groupID, groupsURL)
|
2018-12-13 11:22:53 +00:00
|
|
|
|
2020-11-03 19:50:09 +00:00
|
|
|
c := conn{
|
|
|
|
Host: keystoneURL, Domain: testDomain,
|
|
|
|
AdminUsername: adminUser, AdminPassword: adminPass,
|
|
|
|
}
|
2018-12-13 11:22:53 +00:00
|
|
|
s := connector.Scopes{OfflineAccess: true, Groups: true}
|
|
|
|
|
|
|
|
identityLogin, _, err := c.Login(context.Background(), s, adminUser, adminPass)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
identityRefresh, err := c.Refresh(context.Background(), s, identityLogin)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
expectEquals(t, 1, len(identityRefresh.Groups))
|
2019-12-18 14:56:46 +00:00
|
|
|
expectEquals(t, testGroup, identityRefresh.Groups[0])
|
2018-11-27 10:28:46 +00:00
|
|
|
}
|
|
|
|
|
2018-12-13 11:22:53 +00:00
|
|
|
func TestUseRefreshTokenUserDeleted(t *testing.T) {
|
2018-12-20 16:25:22 +00:00
|
|
|
setupVariables(t)
|
2018-12-13 11:22:53 +00:00
|
|
|
token, _ := getAdminToken(t, adminUser, adminPass)
|
|
|
|
userID := createUser(t, token, testUser, testEmail, testPass)
|
|
|
|
|
2020-11-03 19:50:09 +00:00
|
|
|
c := conn{
|
|
|
|
Host: keystoneURL, Domain: testDomain,
|
|
|
|
AdminUsername: adminUser, AdminPassword: adminPass,
|
|
|
|
}
|
2018-12-13 11:22:53 +00:00
|
|
|
s := connector.Scopes{OfflineAccess: true, Groups: true}
|
|
|
|
|
|
|
|
identityLogin, _, err := c.Login(context.Background(), s, testUser, testPass)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = c.Refresh(context.Background(), s, identityLogin)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err.Error())
|
|
|
|
}
|
|
|
|
|
2020-04-06 13:40:17 +00:00
|
|
|
deleteResource(t, token, userID, usersURL)
|
2018-12-13 11:22:53 +00:00
|
|
|
_, err = c.Refresh(context.Background(), s, identityLogin)
|
|
|
|
|
|
|
|
if !strings.Contains(err.Error(), "does not exist") {
|
|
|
|
t.Errorf("unexpected error: %s", err.Error())
|
|
|
|
}
|
2018-11-27 10:28:46 +00:00
|
|
|
}
|
|
|
|
|
2018-12-13 11:22:53 +00:00
|
|
|
func TestUseRefreshTokenGroupsChanged(t *testing.T) {
|
2018-12-20 16:25:22 +00:00
|
|
|
setupVariables(t)
|
2018-12-13 11:22:53 +00:00
|
|
|
token, _ := getAdminToken(t, adminUser, adminPass)
|
|
|
|
userID := createUser(t, token, testUser, testEmail, testPass)
|
2020-04-06 13:40:17 +00:00
|
|
|
defer deleteResource(t, token, userID, usersURL)
|
2018-12-13 11:22:53 +00:00
|
|
|
|
2020-11-03 19:50:09 +00:00
|
|
|
c := conn{
|
|
|
|
Host: keystoneURL, Domain: testDomain,
|
|
|
|
AdminUsername: adminUser, AdminPassword: adminPass,
|
|
|
|
}
|
2018-12-13 11:22:53 +00:00
|
|
|
s := connector.Scopes{OfflineAccess: true, Groups: true}
|
|
|
|
|
|
|
|
identityLogin, _, err := c.Login(context.Background(), s, testUser, testPass)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
identityRefresh, err := c.Refresh(context.Background(), s, identityLogin)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
expectEquals(t, 0, len(identityRefresh.Groups))
|
|
|
|
|
2018-12-20 16:25:22 +00:00
|
|
|
groupID := createGroup(t, token, "Test group", testGroup)
|
2018-12-13 11:22:53 +00:00
|
|
|
addUserToGroup(t, token, groupID, userID)
|
2020-04-06 13:40:17 +00:00
|
|
|
defer deleteResource(t, token, groupID, groupsURL)
|
2018-12-13 11:22:53 +00:00
|
|
|
|
|
|
|
identityRefresh, err = c.Refresh(context.Background(), s, identityLogin)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
expectEquals(t, 1, len(identityRefresh.Groups))
|
2018-11-27 10:28:46 +00:00
|
|
|
}
|
|
|
|
|
2018-12-20 16:25:22 +00:00
|
|
|
func TestNoGroupsInScope(t *testing.T) {
|
|
|
|
setupVariables(t)
|
|
|
|
token, _ := getAdminToken(t, adminUser, adminPass)
|
|
|
|
userID := createUser(t, token, testUser, testEmail, testPass)
|
2020-04-06 13:40:17 +00:00
|
|
|
defer deleteResource(t, token, userID, usersURL)
|
2018-12-20 16:25:22 +00:00
|
|
|
|
2020-11-03 19:50:09 +00:00
|
|
|
c := conn{
|
|
|
|
Host: keystoneURL, Domain: testDomain,
|
|
|
|
AdminUsername: adminUser, AdminPassword: adminPass,
|
|
|
|
}
|
2018-12-20 16:25:22 +00:00
|
|
|
s := connector.Scopes{OfflineAccess: true, Groups: false}
|
|
|
|
|
|
|
|
groupID := createGroup(t, token, "Test group", testGroup)
|
|
|
|
addUserToGroup(t, token, groupID, userID)
|
2020-04-06 13:40:17 +00:00
|
|
|
defer deleteResource(t, token, groupID, groupsURL)
|
2018-12-20 16:25:22 +00:00
|
|
|
|
|
|
|
identityLogin, _, err := c.Login(context.Background(), s, testUser, testPass)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err.Error())
|
|
|
|
}
|
|
|
|
expectEquals(t, 0, len(identityLogin.Groups))
|
|
|
|
|
|
|
|
identityRefresh, err := c.Refresh(context.Background(), s, identityLogin)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err.Error())
|
|
|
|
}
|
|
|
|
expectEquals(t, 0, len(identityRefresh.Groups))
|
|
|
|
}
|
|
|
|
|
|
|
|
func setupVariables(t *testing.T) {
|
2018-12-13 11:22:53 +00:00
|
|
|
keystoneURLEnv := "DEX_KEYSTONE_URL"
|
|
|
|
keystoneAdminURLEnv := "DEX_KEYSTONE_ADMIN_URL"
|
2018-12-20 16:25:22 +00:00
|
|
|
keystoneAdminUserEnv := "DEX_KEYSTONE_ADMIN_USER"
|
|
|
|
keystoneAdminPassEnv := "DEX_KEYSTONE_ADMIN_PASS"
|
2018-12-13 11:22:53 +00:00
|
|
|
keystoneURL = os.Getenv(keystoneURLEnv)
|
|
|
|
if keystoneURL == "" {
|
2018-12-20 16:25:22 +00:00
|
|
|
t.Skip(fmt.Sprintf("variable %q not set, skipping keystone connector tests\n", keystoneURLEnv))
|
2018-12-13 11:22:53 +00:00
|
|
|
return
|
|
|
|
}
|
2018-12-20 16:25:22 +00:00
|
|
|
keystoneAdminURL = os.Getenv(keystoneAdminURLEnv)
|
2018-12-13 11:22:53 +00:00
|
|
|
if keystoneAdminURL == "" {
|
2018-12-20 16:25:22 +00:00
|
|
|
t.Skip(fmt.Sprintf("variable %q not set, skipping keystone connector tests\n", keystoneAdminURLEnv))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
adminUser = os.Getenv(keystoneAdminUserEnv)
|
|
|
|
if adminUser == "" {
|
|
|
|
t.Skip(fmt.Sprintf("variable %q not set, skipping keystone connector tests\n", keystoneAdminUserEnv))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
adminPass = os.Getenv(keystoneAdminPassEnv)
|
|
|
|
if adminPass == "" {
|
|
|
|
t.Skip(fmt.Sprintf("variable %q not set, skipping keystone connector tests\n", keystoneAdminPassEnv))
|
2018-12-13 11:22:53 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
authTokenURL = keystoneURL + "/v3/auth/tokens/"
|
|
|
|
usersURL = keystoneAdminURL + "/v3/users/"
|
|
|
|
groupsURL = keystoneAdminURL + "/v3/groups/"
|
2018-11-27 10:28:46 +00:00
|
|
|
}
|
2018-12-13 11:22:53 +00:00
|
|
|
|
|
|
|
func expectEquals(t *testing.T, a interface{}, b interface{}) {
|
|
|
|
if !reflect.DeepEqual(a, b) {
|
|
|
|
t.Errorf("Expected %v to be equal %v", a, b)
|
|
|
|
}
|
|
|
|
}
|