forked from rancher/rancher
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add auth provider init generic table validation tests, move openldap …
…to its own package under provider
- Loading branch information
1 parent
37299f4
commit 3677900
Showing
4 changed files
with
582 additions
and
19 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
tests/v2/validation/auth/openldap.go → ...dation/auth/provider/openldap/openldap.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package auth | ||
package openldap | ||
|
||
import ( | ||
"context" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package provider | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
"time" | ||
|
||
"github.com/rancher/shepherd/clients/rancher" | ||
"github.com/rancher/shepherd/clients/rancher/auth" | ||
v3 "github.com/rancher/shepherd/clients/rancher/generated/management/v3" | ||
"github.com/stretchr/testify/require" | ||
kwait "k8s.io/apimachinery/pkg/util/wait" | ||
) | ||
|
||
const ConfigurationFileKey = "authInput" | ||
|
||
type User struct { | ||
Username string `json:"username,omitempty" yaml:"username,omitempty"` | ||
Password string `json:"password,omitempty" yaml:"password,omitempty"` | ||
} | ||
|
||
type AuthConfig struct { | ||
Group string `json:"group,omitempty" yaml:"group,omitempty"` | ||
Users []User `json:"users,omitempty" yaml:"users,omitempty"` | ||
NestedGroup string `json:"nestedGroup,omitempty" yaml:"nestedGroup,omitempty"` | ||
NestedUsers []User `json:"nestedUsers,omitempty" yaml:"nestedUsers,omitempty"` | ||
DoubleNestedGroup string `json:"doubleNestedGroup,omitempty" yaml:"doubleNestedGroup,omitempty"` | ||
DoubleNestedUsers []User `json:"doubleNestedUsers,omitempty" yaml:"doubleNestedUsers,omitempty"` | ||
} | ||
|
||
const ( | ||
passwordSecretID = "cattle-global-data/openldapconfig-serviceaccountpassword" | ||
authProvCleanupAnnotationKey = "management.cattle.io/auth-provider-cleanup" | ||
authProvCleanupAnnotationValLocked = "rancher-locked" | ||
authProvCleanupAnnotationValUnlocked = "unlocked" | ||
) | ||
|
||
func waitUntilAnnotationIsUpdated(client *rancher.Client) (*v3.AuthConfig, error) { | ||
ldapConfig, err := client.Management.AuthConfig.ByID("openldap") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
err = kwait.PollUntilContextTimeout(context.TODO(), 500*time.Millisecond, 2*time.Minute, true, func(context.Context) (bool, error) { | ||
newLDAPConfig, err := client.Management.AuthConfig.ByID("openldap") | ||
if err != nil { | ||
return false, nil | ||
} | ||
|
||
if ldapConfig.Annotations[authProvCleanupAnnotationKey] != newLDAPConfig.Annotations[authProvCleanupAnnotationKey] { | ||
ldapConfig = newLDAPConfig | ||
return true, nil | ||
} | ||
|
||
return false, nil | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return ldapConfig, err | ||
} | ||
|
||
var userEnabled = true | ||
|
||
func login(client *rancher.Client, authProvider auth.Provider, user *v3.User) (*rancher.Client, error) { | ||
user.Enabled = &userEnabled | ||
return client.AsAuthUser(user, authProvider) | ||
} | ||
|
||
func newPrincipalID(authConfigID, principalType, name, searchBase string) string { | ||
return fmt.Sprintf("%v_%v://cn=%v,ou=%vs,%v", authConfigID, principalType, name, principalType, searchBase) | ||
} | ||
|
||
func newWithAccessMode(t *testing.T, client *rancher.Client, authConfigID, accessMode string, allowedPrincipalIDs []string) (existing, updates *v3.AuthConfig) { | ||
t.Helper() | ||
|
||
existing, err := client.Management.AuthConfig.ByID(authConfigID) | ||
require.NoError(t, err) | ||
|
||
updates = existing | ||
updates.AccessMode = accessMode | ||
|
||
if allowedPrincipalIDs != nil { | ||
updates.AllowedPrincipalIDs = allowedPrincipalIDs | ||
} | ||
|
||
return | ||
} |
Oops, something went wrong.