mirror of
https://github.com/coder/coder.git
synced 2025-07-08 11:39:50 +00:00
fix(enterprise/cli): correctly set default tags for PSK auth (#9436)
* provisionerd: unconditionally set tag scope to org for psk auth * provisionerd: add unit tests for MutateTags * cli: add some informational logging around provisionerd tags * cli: respect CODER_VERBOSE when initializing logger
This commit is contained in:
80
coderd/provisionerdserver/provisionertags_test.go
Normal file
80
coderd/provisionerdserver/provisionertags_test.go
Normal file
@ -0,0 +1,80 @@
|
||||
package provisionerdserver_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/coder/coder/v2/coderd/provisionerdserver"
|
||||
)
|
||||
|
||||
func TestMutateTags(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testUserID := uuid.New()
|
||||
|
||||
for _, tt := range []struct {
|
||||
name string
|
||||
userID uuid.UUID
|
||||
tags map[string]string
|
||||
want map[string]string
|
||||
}{
|
||||
{
|
||||
name: "nil tags",
|
||||
userID: uuid.Nil,
|
||||
tags: nil,
|
||||
want: map[string]string{
|
||||
provisionerdserver.TagScope: provisionerdserver.ScopeOrganization,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "empty tags",
|
||||
userID: uuid.Nil,
|
||||
tags: map[string]string{},
|
||||
want: map[string]string{
|
||||
provisionerdserver.TagScope: provisionerdserver.ScopeOrganization,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "user scope",
|
||||
tags: map[string]string{provisionerdserver.TagScope: provisionerdserver.ScopeUser},
|
||||
userID: testUserID,
|
||||
want: map[string]string{
|
||||
provisionerdserver.TagScope: provisionerdserver.ScopeUser,
|
||||
provisionerdserver.TagOwner: testUserID.String(),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "organization scope",
|
||||
tags: map[string]string{provisionerdserver.TagScope: provisionerdserver.ScopeOrganization},
|
||||
userID: testUserID,
|
||||
want: map[string]string{
|
||||
provisionerdserver.TagScope: provisionerdserver.ScopeOrganization,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "invalid scope",
|
||||
tags: map[string]string{provisionerdserver.TagScope: "360noscope"},
|
||||
userID: testUserID,
|
||||
want: map[string]string{
|
||||
provisionerdserver.TagScope: provisionerdserver.ScopeOrganization,
|
||||
},
|
||||
},
|
||||
} {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
// make a copy of the map because the function under test
|
||||
// mutates the map
|
||||
bytes, err := json.Marshal(tt.tags)
|
||||
require.NoError(t, err)
|
||||
var tags map[string]string
|
||||
err = json.Unmarshal(bytes, &tags)
|
||||
require.NoError(t, err)
|
||||
got := provisionerdserver.MutateTags(tt.userID, tags)
|
||||
require.Equal(t, tt.want, got)
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user