coderdtest

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2022 License: AGPL-3.0 Imports: 60 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FirstUserParams = codersdk.CreateFirstUserRequest{
	Email:            "testuser@coder.com",
	Username:         "testuser",
	Password:         "testpass",
	OrganizationName: "testorg",
}

Functions

func AGPLRoutes added in v0.8.7

func AGPLRoutes(a *AuthTester) (map[string]string, map[string]RouteCheck)

func AwaitTemplateVersionJob added in v0.4.0

func AwaitTemplateVersionJob(t *testing.T, client *codersdk.Client, version uuid.UUID) codersdk.TemplateVersion

AwaitTemplateImportJob awaits for an import job to reach completed status.

func AwaitWorkspaceAgents

func AwaitWorkspaceAgents(t *testing.T, client *codersdk.Client, workspaceID uuid.UUID) []codersdk.WorkspaceResource

AwaitWorkspaceAgents waits for all resources with agents to be connected.

func AwaitWorkspaceBuildJob

func AwaitWorkspaceBuildJob(t *testing.T, client *codersdk.Client, build uuid.UUID) codersdk.WorkspaceBuild

AwaitWorkspaceBuildJob waits for a workspace provision job to reach completed status.

func CreateAnotherUser

func CreateAnotherUser(t *testing.T, client *codersdk.Client, organizationID uuid.UUID, roles ...string) *codersdk.Client

CreateAnotherUser creates and authenticates a new user.

func CreateAnotherUserWithUser added in v0.8.5

func CreateAnotherUserWithUser(t *testing.T, client *codersdk.Client, organizationID uuid.UUID, roles ...string) (*codersdk.Client, codersdk.User)

func CreateFirstUser

func CreateFirstUser(t *testing.T, client *codersdk.Client) codersdk.CreateFirstUserResponse

CreateFirstUser creates a user with preset credentials and authenticates with the passed in codersdk client.

func CreateTemplate added in v0.4.0

func CreateTemplate(t *testing.T, client *codersdk.Client, organization uuid.UUID, version uuid.UUID, mutators ...func(*codersdk.CreateTemplateRequest)) codersdk.Template

CreateTemplate creates a template with the "echo" provisioner for compatibility with testing. The name assigned is randomly generated.

func CreateTemplateVersion added in v0.4.0

func CreateTemplateVersion(t *testing.T, client *codersdk.Client, organizationID uuid.UUID, res *echo.Responses) codersdk.TemplateVersion

CreateTemplateVersion creates a template import provisioner job with the responses provided. It uses the "echo" provisioner for compatibility with testing.

func CreateWorkspace

func CreateWorkspace(t *testing.T, client *codersdk.Client, organization uuid.UUID, templateID uuid.UUID, mutators ...func(*codersdk.CreateWorkspaceRequest)) codersdk.Workspace

CreateWorkspace creates a workspace for the user and template provided. A random name is generated for it. To customize the defaults, pass a mutator func.

func CreateWorkspaceBuild added in v0.6.0

func CreateWorkspaceBuild(
	t *testing.T,
	client *codersdk.Client,
	workspace codersdk.Workspace,
	transition database.WorkspaceTransition,
) codersdk.WorkspaceBuild

CreateWorkspaceBuild creates a workspace build for the given workspace and transition.

func MustTransitionWorkspace added in v0.6.3

func MustTransitionWorkspace(t *testing.T, client *codersdk.Client, workspaceID uuid.UUID, from, to database.WorkspaceTransition) codersdk.Workspace

TransitionWorkspace is a convenience method for transitioning a workspace from one state to another.

func MustWorkspace added in v0.6.3

func MustWorkspace(t *testing.T, client *codersdk.Client, workspaceID uuid.UUID) codersdk.Workspace

MustWorkspace is a convenience method for fetching a workspace that should exist.

func New

func New(t *testing.T, options *Options) *codersdk.Client

New constructs a codersdk client connected to an in-memory API instance.

func NewAWSInstanceIdentity

func NewAWSInstanceIdentity(t *testing.T, instanceID string) (awsidentity.Certificates, *http.Client)

NewAWSInstanceIdentity returns a metadata client and ID token validator for faking instance authentication for AWS.

func NewAzureInstanceIdentity added in v0.4.4

func NewAzureInstanceIdentity(t *testing.T, instanceID string) (x509.VerifyOptions, *http.Client)

NewAzureInstanceIdentity returns a metadata client and ID token validator for faking instance authentication for Azure.

func NewGoogleInstanceIdentity

func NewGoogleInstanceIdentity(t *testing.T, instanceID string, expired bool) (*idtoken.Validator, *metadata.Client)

NewGoogleInstanceIdentity returns a metadata client and ID token validator for faking instance authentication for Google Cloud. nolint:revive

func NewOptions added in v0.9.0

func NewOptions(t *testing.T, options *Options) (*httptest.Server, context.CancelFunc, *coderd.Options)

func NewProvisionerDaemon

func NewProvisionerDaemon(t *testing.T, coderAPI *coderd.API) io.Closer

NewProvisionerDaemon launches a provisionerd instance configured to work well with coderd testing. It registers the "echo" provisioner for quick testing.

func NewWithAPI added in v0.6.1

func NewWithAPI(t *testing.T, options *Options) (*codersdk.Client, io.Closer, *coderd.API)

NewWithAPI constructs an in-memory API instance and returns a client to talk to it. Most tests never need a reference to the API, but AuthorizationTest in this module uses it. Do not expose the API or wrath shall descend upon thee.

func NewWithProvisionerCloser added in v0.7.6

func NewWithProvisionerCloser(t *testing.T, options *Options) (*codersdk.Client, io.Closer)

NewWithProvisionerCloser returns a client as well as a handle to close the provisioner. This is a temporary function while work is done to standardize how provisioners are registered with coderd. The option to include a provisioner is set to true for convenience.

func SDKError added in v0.8.12

func SDKError(t *testing.T, err error) *codersdk.Error

SDKError coerces err into an SDK error.

func UpdateTemplateVersion added in v0.5.6

func UpdateTemplateVersion(t *testing.T, client *codersdk.Client, organizationID uuid.UUID, res *echo.Responses, templateID uuid.UUID) codersdk.TemplateVersion

UpdateTemplateVersion creates a new template version with the "echo" provisioner and associates it with the given templateID.

Types

type AuthTester added in v0.8.7

type AuthTester struct {
	Client                *codersdk.Client
	Workspace             codersdk.Workspace
	Organization          codersdk.Organization
	Admin                 codersdk.CreateFirstUserResponse
	Template              codersdk.Template
	Version               codersdk.TemplateVersion
	WorkspaceResource     codersdk.WorkspaceResource
	File                  codersdk.UploadResponse
	TemplateVersionDryRun codersdk.ProvisionerJob
	TemplateParam         codersdk.Parameter
	URLParams             map[string]string
	// contains filtered or unexported fields
}

func NewAuthTester added in v0.8.7

func NewAuthTester(ctx context.Context, t *testing.T, client *codersdk.Client, api *coderd.API, admin codersdk.CreateFirstUserResponse) *AuthTester

func (*AuthTester) Test added in v0.8.7

func (a *AuthTester) Test(ctx context.Context, assertRoute map[string]RouteCheck, skipRoutes map[string]string)

type Options

type Options struct {
	AppHostname          string
	AWSCertificates      awsidentity.Certificates
	Authorizer           rbac.Authorizer
	AzureCertificates    x509.VerifyOptions
	GithubOAuth2Config   *coderd.GithubOAuth2Config
	OIDCConfig           *coderd.OIDCConfig
	GoogleTokenValidator *idtoken.Validator
	SSHKeygenAlgorithm   gitsshkey.Algorithm
	APIRateLimit         int
	AutoImportTemplates  []coderd.AutoImportTemplate
	AutobuildTicker      <-chan time.Time
	AutobuildStats       chan<- executor.Stats
	Auditor              audit.Auditor

	// IncludeProvisionerDaemon when true means to start an in-memory provisionerD
	IncludeProvisionerDaemon    bool
	MetricsCacheRefreshInterval time.Duration
	AgentStatsRefreshInterval   time.Duration
}

type RecordingAuthorizer added in v0.9.0

type RecordingAuthorizer struct {
	Called       *authCall
	AlwaysReturn error
}

func (*RecordingAuthorizer) ByRoleName added in v0.9.0

func (r *RecordingAuthorizer) ByRoleName(_ context.Context, subjectID string, roleNames []string, scope rbac.Scope, action rbac.Action, object rbac.Object) error

func (*RecordingAuthorizer) ByRoleNameSQL added in v0.9.3

func (r *RecordingAuthorizer) ByRoleNameSQL(_ context.Context, _ string, _ []string, _ rbac.Scope, _ rbac.Action, _ rbac.Object) error

ByRoleNameSQL does not record the call. This matches the postgres behavior of not calling Authorize()

func (*RecordingAuthorizer) PrepareByRoleName added in v0.9.0

func (r *RecordingAuthorizer) PrepareByRoleName(_ context.Context, subjectID string, roles []string, scope rbac.Scope, action rbac.Action, _ string) (rbac.PreparedAuthorized, error)

type RouteCheck added in v0.8.7

type RouteCheck struct {
	NoAuthorize  bool
	AssertAction rbac.Action
	AssertObject rbac.Object
	StatusCode   int
}

Jump to

Keyboard shortcuts

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