@@ -52,7 +52,10 @@ func dbauthzAuthorizationContext(m dsl.Matcher) {
52
52
func testingWithOwnerUser (m dsl.Matcher ) {
53
53
m .Import ("testing" )
54
54
m .Import ("github.com/coder/coder/v2/cli/clitest" )
55
+ m .Import ("github.com/coder/coder/v2/enterprise/coderd/coderenttest" )
55
56
57
+ // For the AGPL code, we just check for SetupConfig being called with a
58
+ // client authenticated as the Owner user.
56
59
m .Match (`
57
60
$_ := coderdtest.CreateFirstUser($t, $client)
58
61
$*_
@@ -63,6 +66,30 @@ func testingWithOwnerUser(m dsl.Matcher) {
63
66
m .File ().Name .Matches (`_test\.go$` )).
64
67
At (m ["SetupConfig" ]).
65
68
Report (`The CLI will be operating as the owner user, which has unrestricted permissions. Consider creating a different user.` )
69
+
70
+ // For the enterprise code, we check for any method called on the client.
71
+ // While we want to be a bit stricter here, some methods are known to require
72
+ // the owner user, so we exclude them.
73
+ m .Match (`
74
+ $client, $_ := coderdenttest.New($t, $*_)
75
+ $*_
76
+ $_, $_ := $client.$Method($*_)
77
+ ` ).Where (m ["t" ].Type .Implements ("testing.TB" ) &&
78
+ m .File ().Name .Matches (`_test\.go$` ) &&
79
+ ! m ["Method" ].Text .Matches (`^(UpdateAppearance|AddLicense|InsertLicense|DeleteLicense|CreateWorkspaceProxy|Replicas|Regions)$` )).
80
+ At (m ["Method" ]).
81
+ Report (`The CLI will be operating as the owner user, which has unrestricted permissions. Consider creating a different user.` )
82
+
83
+ // Sadly, we need to match both one- and two-valued assignments separately.
84
+ m .Match (`
85
+ $client, $_ := coderdenttest.New($t, $*_)
86
+ $*_
87
+ $_ := $client.$Method($*_)
88
+ ` ).Where (m ["t" ].Type .Implements ("testing.TB" ) &&
89
+ m .File ().Name .Matches (`_test\.go$` ) &&
90
+ ! m ["Method" ].Text .Matches (`^(UpdateAppearance|AddLicense|InsertLicense|DeleteLicense|CreateWorkspaceProxy|Replicas|Regions)$` )).
91
+ At (m ["Method" ]).
92
+ Report (`The CLI will be operating as the owner user, which has unrestricted permissions. Consider creating a different user.` )
66
93
}
67
94
68
95
// Use xerrors everywhere! It provides additional stacktrace info!
0 commit comments