-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(provider/kubernetes): v2 restrict namespaces for uploading manif…
…ests (#2410)
- Loading branch information
1 parent
6ed3bb0
commit 299d35d
Showing
10 changed files
with
127 additions
and
10 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
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
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
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
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
83 changes: 83 additions & 0 deletions
83
...netflix/spinnaker/clouddriver/kubernetes/v2/validator/KubernetesValidationUtilSpec.groovy
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 |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Copyright 2018 Schibsted ASA. | ||
* | ||
* 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. | ||
*/ | ||
|
||
package com.netflix.spinnaker.clouddriver.kubernetes.v2.validator | ||
|
||
import com.netflix.spinnaker.clouddriver.kubernetes.v2.security.KubernetesV2Credentials | ||
import com.netflix.spinnaker.clouddriver.security.AccountCredentials | ||
import com.netflix.spinnaker.clouddriver.security.AccountCredentialsProvider | ||
import org.springframework.validation.Errors | ||
import spock.lang.Specification | ||
import spock.lang.Unroll | ||
|
||
class KubernetesValidationUtilSpec extends Specification { | ||
@Unroll | ||
void "wiring of namespace validation"() { | ||
given: | ||
Errors errors = Mock(Errors) | ||
String kubernetesAccount = "testAccount" | ||
def namespaces = ["test-namespace"] | ||
def omitNamespaces = ["omit-namespace"] | ||
AccountCredentials accountCredentials = Mock(AccountCredentials) | ||
KubernetesV2Credentials credentials = Mock(KubernetesV2Credentials) | ||
KubernetesValidationUtil kubernetesValidationUtil = new KubernetesValidationUtil("currentContext", errors); | ||
AccountCredentialsProvider accountCredentialsProvider = Mock(AccountCredentialsProvider) | ||
|
||
when: | ||
def judgement = kubernetesValidationUtil.validateV2Credentials(accountCredentialsProvider, kubernetesAccount, testNamespace) | ||
|
||
then: | ||
accountCredentialsProvider.getCredentials(kubernetesAccount) >> accountCredentials | ||
accountCredentials.getCredentials() >> credentials | ||
credentials.getOmitNamespaces() >> omitNamespaces | ||
credentials.namespaces >> namespaces | ||
judgement == expectedResult | ||
|
||
where: | ||
testNamespace || expectedResult | ||
"test-namespace" || true | ||
"omit-namespace" || false | ||
"unknown-namespace" || false | ||
} | ||
|
||
@Unroll | ||
void "validation of namespaces"() { | ||
given: | ||
Errors errors = Mock(Errors) | ||
KubernetesV2Credentials credentials = Mock(KubernetesV2Credentials) | ||
KubernetesValidationUtil kubernetesValidationUtil = new KubernetesValidationUtil("currentContext", errors); | ||
|
||
when: | ||
def judgement = kubernetesValidationUtil.validateNamespace(testNamespace, credentials) | ||
|
||
then: | ||
credentials.getOmitNamespaces() >> omitNamespaces | ||
credentials.namespaces >> namespaces | ||
judgement == allowedNamespace | ||
|
||
where: | ||
namespaces | omitNamespaces | testNamespace || allowedNamespace | ||
["test-namespace"] | ["omit-namespace"] | "test-namespace" || true | ||
null | ["omit-namespace"] | "test-namespace" || true | ||
["test-namespace"] | null | "test-namespace" || true | ||
["test-namespace"] | ["omit-namespace"] | "omit-namespace" || false | ||
null | ["omit-namespace"] | "omit-namespace" || false | ||
["test-namespace"] | ["omit-namespace"] | "unknown-namespace" || false | ||
null | null | "unknown-namespace" || true | ||
[] | [] | "unknown-namespace" || true | ||
} | ||
} |