github.com/GoogleContainerTools/skaffold/v2@v2.13.2/integration/binauthz_test.go (about) 1 /* 2 Copyright 2023 The Skaffold Authors 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package integration 18 19 import ( 20 "os" 21 "strings" 22 "testing" 23 24 "github.com/GoogleContainerTools/skaffold/v2/integration/skaffold" 25 ) 26 27 const ( 28 binauthzClusterName = "integration-tests-binauthz" 29 ) 30 31 // TestBinAuthZWithDeploy targets the integration-tests-binauthz cluster on k8s-skaffold which has '--binauthz-evaluation-mode=PROJECT_SINGLETON_POLICY_ENFORCE' set 32 func TestBinAuthZWithDeploy(t *testing.T) { 33 MarkIntegrationTest(t, NeedsGcp) 34 if os.Getenv("GKE_CLUSTER_NAME") != binauthzClusterName { 35 t.Skip("TestBinAuthZWithDeploy only runs against integration-tests-binauthz cluster") 36 } 37 38 ns, _ := SetupNamespace(t) 39 expected := "Failed to create Pod for Deployment" 40 41 // We're not providing a tag for the getting-started image 42 output, err := skaffold.Deploy("--images", "index.docker.io/library/busybox:1", "--default-repo=").InDir("examples/kustomize").InNs(ns.Name).RunWithCombinedOutput(t) 43 if err == nil { 44 t.Errorf("expected to see an error since the image deployed to cluster should be denied based on binauthz policy: %s", output) 45 } else if !strings.Contains(string(output), expected) { 46 t.Errorf("unexpected error text - expected: %s, got: %s", expected, output) 47 } 48 }