Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add unit tests
  • Loading branch information
Emyrk committed Mar 31, 2023
commit dff4fc8dd2819d82f807094bc8363673cfecd999
1 change: 1 addition & 0 deletions enterprise/audit/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ var auditableResourcesTypes = map[any]map[string]Action{
"id": ActionTrack,
"organization_id": ActionTrack,
"name": ActionTrack,
"display_name": ActionTrack,
"icon": ActionTrack,
"url": ActionTrack,
"wildcard_url": ActionTrack,
Expand Down
81 changes: 81 additions & 0 deletions enterprise/coderd/workspaceproxy_internal_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package coderd

import (
"testing"

"github.com/stretchr/testify/require"
)

func Test_validateProxyURL(t *testing.T) {
t.Parallel()

testcases := []struct {
Name string
URL string
Wild bool
ExpectedError bool
}{
{
Name: "Empty",
URL: "",
Wild: false,
ExpectedError: true,
},
{
Name: "EmptyWild",
URL: "",
Wild: true,
ExpectedError: true,
},
{
Name: "URL",
URL: "https://example.com",
Wild: false,
ExpectedError: false,
},
{
Name: "WildcardURL",
URL: "https://*.example.com",
Wild: true,
ExpectedError: false,
},
{
Name: "URLMissingWild",
URL: "https://example.com",
Wild: true,
ExpectedError: true,
},
{
Name: "NoScheme",
URL: "*.example.com",
Wild: true,
ExpectedError: true,
},
{
Name: "BadScheme",
URL: "ssh://*.example.com",
Wild: true,
ExpectedError: true,
},
{
Name: "IncludePaths",
URL: "https://*.example.com/test",
Wild: true,
ExpectedError: true,
},
}

for _, tt := range testcases {
tt := tt
t.Run(tt.Name, func(t *testing.T) {
t.Parallel()

err := validateProxyURL(tt.URL, tt.Wild)
if tt.ExpectedError {
require.Error(t, err)
} else {
require.NoError(t, err)
}
})
}
}