test

package
v2.14.11+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 11, 2021 License: Apache-2.0 Imports: 50 Imported by: 11

Documentation

Index

Constants

View Source
const (
	// AuthorizationCode represents a shared secret used by IssuerVerifier
	// TODO: consider injecting it into IssuerVerifier
	AuthorizationCode = "fakeCode"
	// IDToken represents a shared fake token
	IDToken       = "fakeTokenId"
	IDViewerToken = "fakeViewerTokenId"

	// IssuerURL holds test issuer URL
	IssuerURL = "url://dex"
	// IssuerClientID holds test issuer client ID
	IssuerClientID = "kubermatic"
	// IssuerClientSecret holds test issuer client secret
	IssuerClientSecret = "secret"
)
View Source
const (
	NoExistingFakeProject      = "NoExistingFakeProject"
	NoExistingFakeProjectID    = "NoExistingFakeProject-ID"
	ForbiddenFakeProject       = "ForbiddenFakeProject"
	ForbiddenFakeProjectID     = "ForbiddenFakeProject-ID"
	ExistingFakeProject        = "ExistingFakeProject"
	ExistingFakeProjectID      = "ExistingFakeProject-ID"
	ImpersonatedClientErrorMsg = "forbidden"
)
View Source
const (
	// UserID holds a test user ID
	UserID = "1233"
	// UserID2 holds a test user ID
	UserID2 = "1523"
	// UserName holds a test user name
	UserName = "user1"
	// UserName2 holds a test user name
	UserName2 = "user2"
	// UserEmail holds a test user email
	UserEmail = "john@acme.com"
	// UserEmail2 holds a test user email
	UserEmail2 = "bob@example.com"
	// ClusterID holds the test cluster ID
	ClusterID = "AbcClusterID"
	// DefaultClusterID holds the test default cluster ID
	DefaultClusterID = "defClusterID"
	// DefaultClusterName holds the test default cluster name
	DefaultClusterName = "defClusterName"
	// ProjectName holds the test project ID
	ProjectName = "my-first-project-ID"
	// TestDatacenter holds datacenter name
	TestSeedDatacenter = "us-central1"
	// TestServiceAccountHashKey authenticates the service account's token value using HMAC
	TestServiceAccountHashKey = "eyJhbGciOiJIUzI1NeyJhbGciOiJIUzI1N"
	// TestFakeToken signed JWT token with fake data
	TestFakeToken = "" /* 193-byte string literal not displayed */
	// TestOSdomain OpenStack domain
	TestOSdomain = "OSdomain"
	// TestOSuserPass OpenStack user password
	TestOSuserPass = "OSpass"
	// TestOSuserName OpenStack user name
	TestOSuserName = "OSuser"
	// TestFakeCredential Fake provider credential name
	TestFakeCredential = "fake"
	// RequiredEmailDomain required domain for predefined credentials
	RequiredEmailDomain = "acme.com"
)

Variables

This section is empty.

Functions

func APIUserToKubermaticUser

func APIUserToKubermaticUser(user apiv1.User) *kubermaticv1.User

APIUserToKubermaticUser simply converts apiv1.User to kubermaticv1.User type

func BuildSeeds

func BuildSeeds() provider.SeedsGetter

func CheckStatusCode

func CheckStatusCode(wantStatusCode int, recorder *httptest.ResponseRecorder, t *testing.T)

func CompareVersions

func CompareVersions(t *testing.T, versions, expected []*apiv1.MasterVersion)

func CompareWithResult

func CompareWithResult(t *testing.T, res *httptest.ResponseRecorder, response string)

CompareWithResult a convenience function for comparing http.Body content with response

func CreateTestEndpoint

func CreateTestEndpoint(user apiv1.User, kubeObjects, kubermaticObjects []runtime.Object, versions []*version.Version, updates []*version.Update, routingFunc newRoutingFunc) (http.Handler, error)

CreateTestEndpoint does exactly the same as CreateTestEndpointAndGetClients except it omits ClientsSets when returning

func DefaultCreationTimestamp

func DefaultCreationTimestamp() time.Time

DefaultCreationTimestamp returns default test timestamp

func GenAPIUser

func GenAPIUser(name, email string) *apiv1.User

GenAPIUser generates a API user

func GenBinding

func GenBinding(projectID, email, group string) *kubermaticv1.UserProjectBinding

GenBinding generates a binding

func GenBlacklistTokenSecret

func GenBlacklistTokenSecret(name string, tokens []byte) *corev1.Secret

func GenCluster

func GenCluster(id string, name string, projectID string, creationTime time.Time, modifiers ...func(*kubermaticv1.Cluster)) *kubermaticv1.Cluster

func GenDefaultAPIUser

func GenDefaultAPIUser() *apiv1.User

GenDefaultAPIUser generates a default API user

func GenDefaultAdminAPIUser

func GenDefaultAdminAPIUser() *apiv1.User

GenDefaultAdminAPIUser generates a default admin API user

func GenDefaultCluster

func GenDefaultCluster() *kubermaticv1.Cluster

func GenDefaultExpiry

func GenDefaultExpiry() (apiv1.Time, error)

func GenDefaultKubermaticObjects

func GenDefaultKubermaticObjects(objs ...runtime.Object) []runtime.Object

GenDefaultKubermaticObjects generates default kubermatic object

func GenDefaultOwnerBinding

func GenDefaultOwnerBinding() *kubermaticv1.UserProjectBinding

GenDefaultOwnerBinding generates default owner binding

func GenDefaultPreset

func GenDefaultPreset() *kubermaticv1.Preset

func GenDefaultProject

func GenDefaultProject() *kubermaticv1.Project

GenDefaultProject generates a default project

func GenDefaultSaToken

func GenDefaultSaToken(projectID, saID, name, id string) *corev1.Secret

func GenDefaultSettings

func GenDefaultSettings() *kubermaticv1.KubermaticSetting

func GenDefaultUser

func GenDefaultUser() *kubermaticv1.User

GenDefaultUser generates a default user

func GenDefaultVersions

func GenDefaultVersions() []*version.Version

func GenInactiveServiceAccount

func GenInactiveServiceAccount(id, name, group, projectName string) *kubermaticv1.User

GenInactiveServiceAccount generates a Service Account resource

func GenProject

func GenProject(name, phase string, creationTime time.Time, oRef ...metav1.OwnerReference) *kubermaticv1.Project

GenProject generates new empty project

func GenServiceAccount

func GenServiceAccount(id, name, group, projectName string) *kubermaticv1.User

func GenTestAddon

func GenTestAddon(name string, variables *runtime.RawExtension, cluster *kubermaticv1.Cluster, creationTime time.Time) *kubermaticv1.Addon

func GenTestEvent

func GenTestEvent(eventName, eventType, eventReason, eventMessage, kind, uid string) *corev1.Event

func GenTestMachine

func GenTestMachine(name, rawProviderSpec string, labels map[string]string, ownerRef []metav1.OwnerReference) *clusterv1alpha1.Machine

func GenTestMachineDeployment

func GenTestMachineDeployment(name, rawProviderSpec string, selector map[string]string, dynamicConfig bool) *clusterv1alpha1.MachineDeployment

func GenTestSeed

func GenTestSeed() *kubermaticv1.Seed

func GenUser

func GenUser(id, name, email string) *kubermaticv1.User

GenUser generates a User resource note if the id is empty then it will be auto generated

func GenerateTestKubeconfig

func GenerateTestKubeconfig(clusterID, token string) string

GenerateTestKubeconfig returns test kubeconfig yaml structure

func GetUser

func GetUser(email, id, name string) apiv1.User

GetUser is a convenience function for generating apiv1.User

Types

type ClientsSets

type ClientsSets struct {
	FakeKubermaticClient *kubermaticfakeclentset.Clientset
	FakeClient           ctrlruntimeclient.Client
	// this client is used for unprivileged methods where impersonated client is used
	FakeKubernetesCoreClient kubernetesclientset.Interface

	TokenAuthenticator serviceaccount.TokenAuthenticator
	TokenGenerator     serviceaccount.TokenGenerator
}

ClientsSets a simple wrapper that holds fake client sets

func CreateTestEndpointAndGetClients

func CreateTestEndpointAndGetClients(user apiv1.User, seedsGetter provider.SeedsGetter, kubeObjects, machineObjects, kubermaticObjects []runtime.Object, versions []*version.Version, updates []*version.Update, routingFunc newRoutingFunc) (http.Handler, *ClientsSets, error)

CreateTestEndpointAndGetClients is a convenience function that instantiates fake providers and sets up routes for the tests

type FakePrivilegedProjectProvider

type FakePrivilegedProjectProvider struct {
}

func NewFakePrivilegedProjectProvider

func NewFakePrivilegedProjectProvider() *FakePrivilegedProjectProvider

func (*FakePrivilegedProjectProvider) DeleteUnsecured

func (f *FakePrivilegedProjectProvider) DeleteUnsecured(projectInternalName string) error

DeleteUnsecured deletes any given project This function is unsafe in a sense that it uses privileged account to delete project with the given name

func (*FakePrivilegedProjectProvider) GetUnsecured

func (f *FakePrivilegedProjectProvider) GetUnsecured(projectInternalName string, options *provider.ProjectGetOptions) (*kubermaticapiv1.Project, error)

GetUnsecured returns the project with the given name This function is unsafe in a sense that it uses privileged account to get project with the given name

func (*FakePrivilegedProjectProvider) UpdateUnsecured

UpdateUnsecured update an existing project and returns it This function is unsafe in a sense that it uses privileged account to update project

type FakeProjectProvider

type FakeProjectProvider struct {
}

func NewFakeProjectProvider

func NewFakeProjectProvider() *FakeProjectProvider

func (*FakeProjectProvider) Delete

func (f *FakeProjectProvider) Delete(userInfo *provider.UserInfo, projectInternalName string) error

Delete deletes the given project as the given user

Note: Before deletion project's status.phase is set to ProjectTerminating

func (*FakeProjectProvider) Get

func (f *FakeProjectProvider) Get(userInfo *provider.UserInfo, projectInternalName string, options *provider.ProjectGetOptions) (*kubermaticapiv1.Project, error)

Get returns the project with the given name

func (*FakeProjectProvider) List

List gets a list of projects, by default it returns all resources. If you want to filter the result please set ProjectListOptions

Note that the list is taken from the cache

func (*FakeProjectProvider) New

func (*FakeProjectProvider) Update

Update update an existing project and returns it

type IssuerVerifier

type IssuerVerifier struct {
	// contains filtered or unexported fields
}

IssuerVerifier is a test stub that mocks OIDC responses

func NewFakeOIDCClient

func NewFakeOIDCClient(user apiv1.User) *IssuerVerifier

NewFakeOIDCClient returns fake OIDC issuer and verifier

func (*IssuerVerifier) AuthCodeURL

func (o *IssuerVerifier) AuthCodeURL(state string, offlineAsScope bool, scopes ...string) string

AuthCodeURL returns a URL to OpenID provider's consent page

func (*IssuerVerifier) Exchange

func (o *IssuerVerifier) Exchange(ctx context.Context, code string) (auth.OIDCToken, error)

Exchange converts an authorization code into a token.

func (*IssuerVerifier) Extract

func (o *IssuerVerifier) Extract(_ *http.Request) (string, error)

Extractor knows how to extract the ID token from the request

func (*IssuerVerifier) Verify

func (o *IssuerVerifier) Verify(ctx context.Context, token string) (auth.TokenClaims, error)

Verify parses a raw ID Token, verifies it's been signed by the provider, preforms any additional checks depending on the Config, and returns the payload as TokenClaims.

type NewAddonSliceWrapper

type NewAddonSliceWrapper []apiv1.Addon

NewAddonSliceWrapper wraps []apiv1.Addon to provide convenient methods for tests

func (*NewAddonSliceWrapper) DecodeOrDie

DecodeOrDie reads and decodes json data from the reader

func (NewAddonSliceWrapper) EqualOrDie

func (k NewAddonSliceWrapper) EqualOrDie(expected NewAddonSliceWrapper, t *testing.T)

EqualOrDie compares whether expected collection is equal to the actual one

func (NewAddonSliceWrapper) Sort

func (k NewAddonSliceWrapper) Sort()

Sort sorts the collection by CreationTimestamp

type NewClusterV1SliceWrapper

type NewClusterV1SliceWrapper []apiv1.Cluster

NewClusterV1SliceWrapper wraps []apiv1.Cluster to provide convenient methods for tests

func (*NewClusterV1SliceWrapper) DecodeOrDie

DecodeOrDie reads and decodes json data from the reader

func (NewClusterV1SliceWrapper) EqualOrDie

func (k NewClusterV1SliceWrapper) EqualOrDie(expected NewClusterV1SliceWrapper, t *testing.T)

EqualOrDie compares whether expected collection is equal to the actual one

func (NewClusterV1SliceWrapper) Sort

func (k NewClusterV1SliceWrapper) Sort()

Sort sorts the collection by CreationTimestamp

type NewRoleNameSliceWrapper

type NewRoleNameSliceWrapper []apiv1.RoleName

NewRoleNameSliceWrapper wraps []apiv1.RoleName to provide convenient methods for tests

func (*NewRoleNameSliceWrapper) DecodeOrDie

DecodeOrDie reads and decodes json data from the reader

func (NewRoleNameSliceWrapper) EqualOrDie

func (k NewRoleNameSliceWrapper) EqualOrDie(expected NewRoleNameSliceWrapper, t *testing.T)

EqualOrDie compares whether expected collection is equal to the actual one

func (NewRoleNameSliceWrapper) Sort

func (k NewRoleNameSliceWrapper) Sort()

Sort sorts the collection by CreationTimestamp

type NewSSHKeyV1SliceWrapper

type NewSSHKeyV1SliceWrapper []apiv1.SSHKey

NewSSHKeyV1SliceWrapper wraps []apiv1.SSHKey to provide convenient methods for tests

func (*NewSSHKeyV1SliceWrapper) DecodeOrDie

DecodeOrDie reads and decodes json data from the reader

func (NewSSHKeyV1SliceWrapper) EqualOrDie

func (k NewSSHKeyV1SliceWrapper) EqualOrDie(expected NewSSHKeyV1SliceWrapper, t *testing.T)

EqualOrDie compares whether expected collection is equal to the actual one

func (NewSSHKeyV1SliceWrapper) Sort

func (k NewSSHKeyV1SliceWrapper) Sort()

Sort sorts the collection by CreationTimestamp

type NewServiceAccountTokenV1SliceWrapper

type NewServiceAccountTokenV1SliceWrapper []apiv1.PublicServiceAccountToken

NewServiceAccountTokenV1SliceWrapper wraps []apiv1.ServiceAccountToken to provide convenient methods for tests

func (*NewServiceAccountTokenV1SliceWrapper) DecodeOrDie

DecodeOrDie reads and decodes json data from the reader

func (NewServiceAccountTokenV1SliceWrapper) EqualOrDie

EqualOrDie compares whether expected collection is equal to the actual one

func (NewServiceAccountTokenV1SliceWrapper) Sort

Sort sorts the collection by name

type NewServiceAccountV1SliceWrapper

type NewServiceAccountV1SliceWrapper []apiv1.ServiceAccount

NewServiceAccountV1SliceWrapper wraps []apiv1.ServiceAccount to provide convenient methods for tests

func (*NewServiceAccountV1SliceWrapper) DecodeOrDie

DecodeOrDie reads and decodes json data from the reader

func (NewServiceAccountV1SliceWrapper) EqualOrDie

EqualOrDie compares whether expected collection is equal to the actual one

func (NewServiceAccountV1SliceWrapper) Sort

Sort sorts the collection by name

type NewUserV1SliceWrapper

type NewUserV1SliceWrapper []apiv1.User

NewUserV1SliceWrapper wraps []apiv1.User to provide convenient methods for tests

func (*NewUserV1SliceWrapper) DecodeOrDie

DecodeOrDie reads and decodes json data from the reader

func (NewUserV1SliceWrapper) EqualOrDie

func (k NewUserV1SliceWrapper) EqualOrDie(expected NewUserV1SliceWrapper, t *testing.T)

EqualOrDie compares whether expected collection is equal to the actual one

func (NewUserV1SliceWrapper) Sort

func (k NewUserV1SliceWrapper) Sort()

Sort sorts the collection by CreationTimestamp

type NodeV1SliceWrapper

type NodeV1SliceWrapper []apiv1.Node

NodeV1SliceWrapper wraps []apiv1.Node to provide convenient methods for tests

func (*NodeV1SliceWrapper) DecodeOrDie

func (k *NodeV1SliceWrapper) DecodeOrDie(r io.Reader, t *testing.T) *NodeV1SliceWrapper

DecodeOrDie reads and decodes json data from the reader

func (NodeV1SliceWrapper) EqualOrDie

func (k NodeV1SliceWrapper) EqualOrDie(expected NodeV1SliceWrapper, t *testing.T)

EqualOrDie compares whether expected collection is equal to the actual one

func (NodeV1SliceWrapper) Sort

func (k NodeV1SliceWrapper) Sort()

Sort sorts the collection by CreationTimestamp

type OicdProvider

type OicdProvider struct {
	// contains filtered or unexported fields
}

OicdProvider is a test stub that mocks *oidc.Provider

func (*OicdProvider) Endpoint

func (p *OicdProvider) Endpoint() oauth2.Endpoint

Endpoint returns the OAuth2 auth and token endpoints for the given provider.

type ProjectV1SliceWrapper

type ProjectV1SliceWrapper []apiv1.Project

ProjectV1SliceWrapper wraps []apiv1.Project to provide convenient methods for tests

func (*ProjectV1SliceWrapper) DecodeOrDie

DecodeOrDie reads and decodes json data from the reader

func (ProjectV1SliceWrapper) EqualOrDie

func (k ProjectV1SliceWrapper) EqualOrDie(expected ProjectV1SliceWrapper, t *testing.T)

EqualOrDie compares whether expected collection is equal to the actual one

func (ProjectV1SliceWrapper) Sort

func (k ProjectV1SliceWrapper) Sort()

Sort sorts the collection by CreationTimestamp

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL