Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a "strict mode" configuration option #2425

Merged
merged 4 commits into from
May 24, 2023
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
64 changes: 64 additions & 0 deletions tests/sdk/nodejs/nodejs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1338,3 +1338,67 @@ func TestServiceAccountTokenSecret(t *testing.T) {
})
integration.ProgramTest(t, &test)
}

func TestStrictMode(t *testing.T) {
test := baseOptions.With(integration.ProgramTestOptions{
Dir: filepath.Join("strict-mode", "step1"),
Quick: true,
ExpectFailure: true,
SkipRefresh: true,
OrderedConfig: []integration.ConfigValue{
{
Key: "kubernetes:strictMode",
Value: "true",
},
},
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
// Check the event stream for a diagnostic event showing that a default provider is prohibited.
foundMessage := false
msg := "strict mode prohibits default provider"
for _, e := range stackInfo.Events {
if e.DiagnosticEvent != nil && strings.Contains(e.DiagnosticEvent.Message, msg) {
foundMessage = true
break
}
}
assert.Truef(t, foundMessage, "did not find expected failure message: %q", msg)
},
EditDirs: []integration.EditDir{
{
Dir: filepath.Join("strict-mode", "step2"),
Additive: true,
ExpectFailure: true,
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
// Check the event stream for a diagnostic event showing that a Provider requires a "context".
foundMessage := false
msg := `strict mode requires Provider "context" argument`
for _, e := range stackInfo.Events {
if e.DiagnosticEvent != nil && strings.Contains(e.DiagnosticEvent.Message, msg) {
foundMessage = true
break
}
}
assert.Truef(t, foundMessage, "did not find expected failure message: %q", msg)
},
},
{
Dir: filepath.Join("strict-mode", "step3"),
Additive: true,
ExpectFailure: true,
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
// Check the event stream for a diagnostic event showing that a Provider requires a "kubeconfig".
foundMessage := false
msg := `strict mode requires Provider "kubeconfig" argument`
for _, e := range stackInfo.Events {
if e.DiagnosticEvent != nil && strings.Contains(e.DiagnosticEvent.Message, msg) {
foundMessage = true
break
}
}
assert.Truef(t, foundMessage, "did not find expected failure message: %q", msg)
},
},
},
})
integration.ProgramTest(t, &test)
}
3 changes: 3 additions & 0 deletions tests/sdk/nodejs/strict-mode/step1/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: strict-mode
description: Tests strict mode provider configuration.
runtime: nodejs
25 changes: 25 additions & 0 deletions tests/sdk/nodejs/strict-mode/step1/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2016-2023, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import * as k8s from "@pulumi/kubernetes";

// This test validates the following restrictions enforced by "strict mode":
// 1. Default providers are not allowed.
// 2. Each Provider requires a "kubeconfig" argument.
// 3. Each Provider requires a "context" argument.

// Create a ConfigMap using the default provider.
new k8s.core.v1.ConfigMap("default", {
data: {foo: "bar"},
});
12 changes: 12 additions & 0 deletions tests/sdk/nodejs/strict-mode/step1/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "strict-mode",
"version": "0.1.0",
"dependencies": {
"@pulumi/pulumi": "latest"
},
"devDependencies": {
},
"peerDependencies": {
"@pulumi/kubernetes": "latest"
}
}
22 changes: 22 additions & 0 deletions tests/sdk/nodejs/strict-mode/step1/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"compilerOptions": {
"outDir": "bin",
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"declaration": true,
"sourceMap": true,
"stripInternal": true,
"experimentalDecorators": true,
"pretty": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"forceConsistentCasingInFileNames": true,
"strictNullChecks": true
},
"files": [
"index.ts"
]
}

25 changes: 25 additions & 0 deletions tests/sdk/nodejs/strict-mode/step2/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2016-2023, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import * as k8s from "@pulumi/kubernetes";

// This test validates the following restrictions enforced by "strict mode":
// 1. Default providers are not allowed.
// 2. Each Provider requires a "context" argument.
// 3. Each Provider requires a "kubeconfig" argument.

// Create a new provider with no context specified.
new k8s.Provider("missingContext", {
lblackstone marked this conversation as resolved.
Show resolved Hide resolved
kubeconfig: "~/.kube/config",
});
25 changes: 25 additions & 0 deletions tests/sdk/nodejs/strict-mode/step3/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2016-2023, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import * as k8s from "@pulumi/kubernetes";

// This test validates the following restrictions enforced by "strict mode":
// 1. Default providers are not allowed.
// 2. Each Provider requires a "context" argument.
// 3. Each Provider requires a "kubeconfig" argument.

// Create a new provider with no kubeconfig specified.
new k8s.Provider("missingKubeconfig", {
context: "test",
});