Skip to content

Commit d50cfaf

Browse files
committed
add a test to ensure users cannot sneak daemons for other users in
1 parent 6fdadca commit d50cfaf

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

enterprise/cli/provisionerdaemons_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,40 @@ func TestProvisionerDaemon_SessionToken(t *testing.T) {
8686
assert.Equal(t, anotherUser.ID.String(), daemons[0].Tags[provisionersdk.TagOwner])
8787
})
8888

89+
t.Run("ScopeAnotherUser", func(t *testing.T) {
90+
t.Parallel()
91+
client, admin := coderdenttest.New(t, &coderdenttest.Options{
92+
ProvisionerDaemonPSK: "provisionersftw",
93+
LicenseOptions: &coderdenttest.LicenseOptions{
94+
Features: license.Features{
95+
codersdk.FeatureExternalProvisionerDaemons: 1,
96+
},
97+
},
98+
})
99+
anotherClient, anotherUser := coderdtest.CreateAnotherUser(t, client, admin.OrganizationID)
100+
inv, conf := newCLI(t, "provisionerd", "start", "--tag", "scope=user", "--tag", "owner="+admin.UserID.String(), "--name", "my-daemon")
101+
clitest.SetupConfig(t, anotherClient, conf)
102+
pty := ptytest.New(t).Attach(inv)
103+
ctx, cancel := context.WithTimeout(inv.Context(), testutil.WaitLong)
104+
defer cancel()
105+
clitest.Start(t, inv)
106+
pty.ExpectMatchContext(ctx, "starting provisioner daemon")
107+
108+
var daemons []codersdk.ProvisionerDaemon
109+
var err error
110+
require.Eventually(t, func() bool {
111+
daemons, err = client.ProvisionerDaemons(ctx)
112+
if err != nil {
113+
return false
114+
}
115+
return len(daemons) == 1
116+
}, testutil.WaitShort, testutil.IntervalSlow)
117+
assert.Equal(t, "my-daemon", daemons[0].Name)
118+
assert.Equal(t, provisionersdk.ScopeUser, daemons[0].Tags[provisionersdk.TagScope])
119+
// This should get clobbered to the user who started the daemon.
120+
assert.Equal(t, anotherUser.ID.String(), daemons[0].Tags[provisionersdk.TagOwner])
121+
})
122+
89123
t.Run("ScopeOrg", func(t *testing.T) {
90124
t.Parallel()
91125
client, admin := coderdenttest.New(t, &coderdenttest.Options{

0 commit comments

Comments
 (0)