MCPcopy Index your code
hub / github.com/coder/coder / TestTemplateAccess

Function TestTemplateAccess

enterprise/coderd/templates_test.go:1965–2177  ·  view source on GitHub ↗

TestTemplateAccess tests the rego -> sql conversion. We need to implement this test on at least 1 table type to ensure that the conversion is correct. The rbac tests only assert against static SQL queries. This is a full rbac test of many of the common role combinations. nolint:tparallel

(t *testing.T)

Source from the content-addressed store, hash-verified

1963//
1964//nolint:tparallel
1965func TestTemplateAccess(t *testing.T) {
1966 t.Parallel()
1967 // TODO: This context is for all the subtests. Each subtest should have its
1968 // own context.
1969 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong*3)
1970 t.Cleanup(cancel)
1971
1972 dv := coderdtest.DeploymentValues(t)
1973 ownerClient, owner := coderdenttest.New(t, &coderdenttest.Options{
1974 Options: &coderdtest.Options{
1975 DeploymentValues: dv,
1976 },
1977 LicenseOptions: &coderdenttest.LicenseOptions{
1978 Features: license.Features{
1979 codersdk.FeatureTemplateRBAC: 1,
1980 codersdk.FeatureMultipleOrganizations: 1,
1981 },
1982 },
1983 })
1984
1985 type coderUser struct {
1986 *codersdk.Client
1987 User codersdk.User
1988 }
1989
1990 type orgSetup struct {
1991 Admin coderUser
1992 MemberInGroup coderUser
1993 MemberNoGroup coderUser
1994
1995 DefaultTemplate codersdk.Template
1996 AllRead codersdk.Template
1997 UserACL codersdk.Template
1998 GroupACL codersdk.Template
1999
2000 Group codersdk.Group
2001 Org codersdk.Organization
2002 }
2003
2004 // Create the following users
2005 // - owner: Site wide owner
2006 // - template-admin
2007 // - org-admin (org 1)
2008 // - org-admin (org 2)
2009 // - org-member (org 1)
2010 // - org-member (org 2)
2011
2012 // Create the following templates in each org
2013 // - template 1, default acls
2014 // - template 2, all_user read
2015 // - template 3, user_acl read for member
2016 // - template 4, group_acl read for groupMember
2017
2018 templateAdmin, _ := coderdtest.CreateAnotherUser(t, ownerClient, owner.OrganizationID, rbac.RoleTemplateAdmin())
2019
2020 makeTemplate := func(t *testing.T, client *codersdk.Client, orgID uuid.UUID, acl codersdk.UpdateTemplateACL) codersdk.Template {
2021 version := coderdtest.CreateTemplateVersion(t, client, orgID, nil)
2022 template := coderdtest.CreateTemplate(t, client, orgID, version.ID)

Callers

nothing calls this directly

Calls 15

DeploymentValuesFunction · 0.92
NewFunction · 0.92
CreateAnotherUserFunction · 0.92
RoleTemplateAdminFunction · 0.92
CreateTemplateVersionFunction · 0.92
CreateTemplateFunction · 0.92
StringFunction · 0.92
ScopedRoleOrgAdminFunction · 0.92
ScopedRoleOrgMemberFunction · 0.92
UpdateTemplateACLMethod · 0.80
CreateOrganizationMethod · 0.80
CreateGroupMethod · 0.80

Tested by

no test coverage detected