Skip to content

Commit b778e12

Browse files
committed
test: Update tests for platform token enabled by default
1 parent 7207973 commit b778e12

File tree

2 files changed

+84
-51
lines changed

2 files changed

+84
-51
lines changed

cmd/monaco/download/download_command_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,17 @@ func TestGetDownloadCommand(t *testing.T) {
8585

8686
t.Run("Download using manifest - access token cannot be specified", func(t *testing.T) {
8787
err := newMonaco(t).download("--token API_TOKEN")
88-
assert.EqualError(t, err, "'--token', '--oauth-client-id', and '--oauth-client-secret' can only be used with '--url', while '--manifest' must NOT be set")
88+
assert.EqualError(t, err, "'--token', '--oauth-client-id', '--oauth-client-secret', and '--platform-token' can only be used with '--url', while '--manifest' must NOT be set")
8989
})
9090

9191
t.Run("Download using manifest - OAuth client ID cannot be specified", func(t *testing.T) {
9292
err := newMonaco(t).download("--oauth-client-id CLIENT_ID")
93-
assert.EqualError(t, err, "'--token', '--oauth-client-id', and '--oauth-client-secret' can only be used with '--url', while '--manifest' must NOT be set")
93+
assert.EqualError(t, err, "'--token', '--oauth-client-id', '--oauth-client-secret', and '--platform-token' can only be used with '--url', while '--manifest' must NOT be set")
9494
})
9595

9696
t.Run("Download using manifest - OAuth client secret cannot be specified", func(t *testing.T) {
9797
err := newMonaco(t).download("--oauth-client-secret CLIENT_SECRET")
98-
assert.EqualError(t, err, "'--token', '--oauth-client-id', and '--oauth-client-secret' can only be used with '--url', while '--manifest' must NOT be set")
98+
assert.EqualError(t, err, "'--token', '--oauth-client-id', '--oauth-client-secret', and '--platform-token' can only be used with '--url', while '--manifest' must NOT be set")
9999
})
100100

101101
t.Run("Download using manifest - platform token cannot be specified", func(t *testing.T) {
@@ -195,6 +195,7 @@ func TestGetDownloadCommand(t *testing.T) {
195195
})
196196

197197
t.Run("Direct download - missing token or OAuth credentials", func(t *testing.T) {
198+
t.Setenv(featureflags.PlatformToken.EnvName(), "false")
198199
err := newMonaco(t).download("--url http://some.url")
199200
assert.EqualError(t, err, "if '--url' is set, '--token' or '--oauth-client-id' and '--oauth-client-secret' must also be set")
200201
})

pkg/manifest/loader/manifest_loader_test.go

Lines changed: 80 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,54 +1869,6 @@ environmentGroups: [{name: b, environments: [{name: c, url: {value: d}}]}]
18691869
`,
18701870
errsContain: []string{ErrNoCredentials.Error()},
18711871
},
1872-
{
1873-
name: "Only platform auth configured with disabled FF",
1874-
manifestContent: platformManifest,
1875-
errsContain: []string{ErrNoCredentials.Error()},
1876-
},
1877-
{
1878-
name: "platform and OAuth configured with disabled FF does not fail",
1879-
manifestContent: platformAndOAuthManifest,
1880-
expectedManifest: manifest.Manifest{
1881-
Projects: map[string]manifest.ProjectDefinition{
1882-
"a": {
1883-
Name: "a",
1884-
Path: "a",
1885-
},
1886-
},
1887-
Environments: manifest.Environments{
1888-
SelectedEnvironments: map[string]manifest.EnvironmentDefinition{
1889-
"c": {
1890-
Name: "c",
1891-
URL: manifest.URLDefinition{
1892-
Type: manifest.ValueURLType,
1893-
Value: "d",
1894-
},
1895-
Group: "b",
1896-
Auth: manifest.Auth{
1897-
OAuth: &manifest.OAuth{
1898-
ClientID: manifest.AuthSecret{
1899-
Name: "client-id",
1900-
Value: "resolved-client-id",
1901-
},
1902-
ClientSecret: manifest.AuthSecret{
1903-
Name: "client-secret",
1904-
Value: "resolved-client-secret",
1905-
},
1906-
},
1907-
},
1908-
},
1909-
},
1910-
AllEnvironmentNames: map[string]struct{}{
1911-
"c": {},
1912-
},
1913-
AllGroupNames: map[string]struct{}{
1914-
"b": {},
1915-
},
1916-
},
1917-
Accounts: map[string]manifest.Account{},
1918-
},
1919-
},
19201872
{
19211873
name: "Unknown type",
19221874
manifestContent: `
@@ -2067,6 +2019,86 @@ environmentGroups: [{name: b, environments: [{name: c, url: {value: d}, auth: {t
20672019
}
20682020
}
20692021

2022+
// TestLoadManifestWithPlatformTokenFeatureFlagDisabled tests manifest loading when platform token FF is explicitly disabled.
2023+
func TestLoadManifestWithPlatformTokenFeatureFlagDisabled(t *testing.T) {
2024+
t.Setenv(featureflags.PlatformToken.EnvName(), "false")
2025+
2026+
t.Setenv("e", "mock token")
2027+
t.Setenv("token-env-var", "mock token")
2028+
t.Setenv("empty-env-var", "")
2029+
t.Setenv("client-id", "resolved-client-id")
2030+
t.Setenv("client-secret", "resolved-client-secret")
2031+
t.Setenv("ENV_OAUTH_ENDPOINT", "resolved-oauth-endpoint")
2032+
2033+
t.Run("Fails if only platform token provided", func(t *testing.T) {
2034+
fs := afero.NewMemMapFs()
2035+
assert.NoError(t, afero.WriteFile(fs, "manifest.yaml", []byte(platformManifest), 0400))
2036+
2037+
mani, errs := Load(&Context{
2038+
Fs: fs,
2039+
ManifestPath: "manifest.yaml",
2040+
})
2041+
2042+
assert.Equal(t, manifest.Manifest{}, mani)
2043+
require.Len(t, errs, 1)
2044+
assert.ErrorContains(t, errs[0], ErrNoCredentials.Error())
2045+
})
2046+
2047+
t.Run("Succeeds if both platform token and oauth provided", func(t *testing.T) {
2048+
2049+
fs := afero.NewMemMapFs()
2050+
assert.NoError(t, afero.WriteFile(fs, "manifest.yaml", []byte(platformAndOAuthManifest), 0400))
2051+
2052+
mani, errs := Load(&Context{
2053+
Fs: fs,
2054+
ManifestPath: "manifest.yaml",
2055+
})
2056+
2057+
expectedManifest := manifest.Manifest{
2058+
Projects: map[string]manifest.ProjectDefinition{
2059+
"a": {
2060+
Name: "a",
2061+
Path: "a",
2062+
},
2063+
},
2064+
Environments: manifest.Environments{
2065+
SelectedEnvironments: map[string]manifest.EnvironmentDefinition{
2066+
"c": {
2067+
Name: "c",
2068+
URL: manifest.URLDefinition{
2069+
Type: manifest.ValueURLType,
2070+
Value: "d",
2071+
},
2072+
Group: "b",
2073+
Auth: manifest.Auth{
2074+
OAuth: &manifest.OAuth{
2075+
ClientID: manifest.AuthSecret{
2076+
Name: "client-id",
2077+
Value: "resolved-client-id",
2078+
},
2079+
ClientSecret: manifest.AuthSecret{
2080+
Name: "client-secret",
2081+
Value: "resolved-client-secret",
2082+
},
2083+
},
2084+
},
2085+
},
2086+
},
2087+
AllEnvironmentNames: map[string]struct{}{
2088+
"c": {},
2089+
},
2090+
AllGroupNames: map[string]struct{}{
2091+
"b": {},
2092+
},
2093+
},
2094+
Accounts: map[string]manifest.Account{},
2095+
}
2096+
2097+
assert.Equal(t, expectedManifest, mani)
2098+
assert.Empty(t, errs)
2099+
})
2100+
}
2101+
20702102
func TestLoadManifest_WithPlatformTokenSupport(t *testing.T) {
20712103
t.Setenv(featureflags.PlatformToken.EnvName(), "true")
20722104
t.Setenv("e", "mock token")

0 commit comments

Comments
 (0)