-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[v17] Fixes unhandled v1 prefixed 'web/config.js' path (#51368)
* Fixes bug where /v1/web/config.js wasn't properly handled because of v1 prefix * Fix lint
- Loading branch information
Showing
2 changed files
with
86 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3585,6 +3585,89 @@ func TestEndpointNotFoundHandling(t *testing.T) { | |
} | ||
} | ||
|
||
func TestKnownWebPathsWithAndWithoutV1Prefix(t *testing.T) { | ||
t.Parallel() | ||
const username = "[email protected]" | ||
// Allow user to create tokens. | ||
roleTokenCRD, err := types.NewRole(services.RoleNameForUser(username), types.RoleSpecV6{ | ||
Allow: types.RoleConditions{ | ||
Rules: []types.Rule{ | ||
types.NewRule(types.KindToken, | ||
[]string{types.VerbCreate}), | ||
}, | ||
}, | ||
}) | ||
require.NoError(t, err) | ||
|
||
env := newWebPack(t, 1) | ||
proxy := env.proxies[0] | ||
pack := proxy.authPack(t, username, []types.Role{roleTokenCRD}) | ||
|
||
res, err := pack.clt.PostJSON(context.Background(), pack.clt.Endpoint("webapi", "token"), types.ProvisionTokenSpecV2{ | ||
Roles: types.SystemRoles{types.RoleNode}, | ||
}) | ||
require.NoError(t, err) | ||
|
||
var responseToken nodeJoinToken | ||
err = json.Unmarshal(res.Bytes(), &responseToken) | ||
require.NoError(t, err) | ||
|
||
tt := []struct { | ||
name string | ||
endpoint string | ||
}{ | ||
{ | ||
name: "web path with prefix", | ||
endpoint: "v1/web/config.js", | ||
}, | ||
{ | ||
name: "web path without prefix", | ||
endpoint: "web/config.js", | ||
}, | ||
{ | ||
name: "webapi path with prefix", | ||
endpoint: "v1/webapi/spiffe/bundle.json", | ||
}, | ||
{ | ||
name: "webapi path without prefix", | ||
endpoint: "webapi/spiffe/bundle.json", | ||
}, | ||
{ | ||
name: ".well-known path with prefix", | ||
endpoint: "v1/.well-known/jwks.json", | ||
}, | ||
{ | ||
name: ".well-known path without prefix", | ||
endpoint: ".well-known/jwks.json", | ||
}, | ||
{ | ||
name: "workload-identity path with prefix", | ||
endpoint: "v1/workload-identity/jwt-jwks.json", | ||
}, | ||
{ | ||
name: "workload-identity path without prefix", | ||
endpoint: "workload-identity/jwt-jwks.json", | ||
}, | ||
{ | ||
name: "scripts path with prefix", | ||
endpoint: fmt.Sprintf("v1/scripts/%s/install-node.sh", responseToken.ID), | ||
}, | ||
{ | ||
name: "scripts path without prefix", | ||
endpoint: fmt.Sprintf("scripts/%s/install-node.sh", responseToken.ID), | ||
}, | ||
} | ||
|
||
for _, tc := range tt { | ||
tc := tc | ||
t.Run(tc.name, func(t *testing.T) { | ||
_, err := pack.clt.Get(context.Background(), fmt.Sprintf("%s/%s", proxy.web.URL, tc.endpoint), url.Values{}) | ||
|
||
require.NoError(t, err) | ||
}) | ||
} | ||
} | ||
|
||
func TestInstallDatabaseScriptGeneration(t *testing.T) { | ||
const username = "[email protected]" | ||
|
||
|