<commit_before>/*
Copyright 2018 The Jetstack cert-manager contributors.

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 certificate

import (
	"time"

	"github.com/jetstack/cert-manager/test/e2e/framework"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	authorizationv1 "k8s.io/api/authorization/v1"
	"k8s.io/api/core/v1"
	rbacv1 "k8s.io/api/rbac/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/client-go/kubernetes"
	"k8s.io/client-go/rest"
)

var _ = framework.CertManagerDescribe("Service Account", func() {
	f := framework.NewDefaultFramework("test-view")

	Context("with read access", func() {
		It("shouldn't be able to create certificates", func() {
			clusterRole := "view"
			verb := "create"
			resource := "certificates"

			hasAccess := rbacClusterRoleHasAccessToResource(f, clusterRole, verb, resource)
			Expect(hasAccess).Should(BeFalse())
		})

		It("should be able to get certificates", func() {
			clusterRole := "view"
			verb := "get"
			resource := "certificates"

			hasAccess := rbacClusterRoleHasAccessToResource(f, clusterRole, verb, resource)
			Expect(hasAccess).Should(BeTrue())
		})
	})
})
<commit_msg>Add comprehensive tests around certificate rbac user facing roles<commit_after>/*
Copyright 2018 The Jetstack cert-manager contributors.

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 certificate

import (
	"time"

	"github.com/jetstack/cert-manager/test/e2e/framework"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	authorizationv1 "k8s.io/api/authorization/v1"
	"k8s.io/api/core/v1"
	rbacv1 "k8s.io/api/rbac/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/client-go/kubernetes"
	"k8s.io/client-go/rest"
)

var _ = framework.CertManagerDescribe("Service Account", func() {
	f := framework.NewDefaultFramework("test-view")

	Context("with namespace view access", func() {
		clusterRole := "view"
		It("shouldn't be able to create certificates", func() {
			verb := "create"
			resource := "certificates"

			hasAccess := rbacClusterRoleHasAccessToResource(f, clusterRole, verb, resource)
			Expect(hasAccess).Should(BeFalse())
		})

		It("shouldn't be able to delete certificates", func() {
			verb := "delete"
			resource := "certificates"

			hasAccess := rbacClusterRoleHasAccessToResource(f, clusterRole, verb, resource)
			Expect(hasAccess).Should(BeFalse())
		})

		It("shouldn't be able to delete collections of certificates", func() {
			verb := "deletecollection"
			resource := "certificates"

			hasAccess := rbacClusterRoleHasAccessToResource(f, clusterRole, verb, resource)
			Expect(hasAccess).Should(BeFalse())
		})

		It("shouldn't be able to patch certificates", func() {
			verb := "patch"
			resource := "certificates"

			hasAccess := rbacClusterRoleHasAccessToResource(f, clusterRole, verb, resource)
			Expect(hasAccess).Should(BeFalse())
		})

		It("shouldn't be able to update certificates", func() {
			verb := "update"
			resource := "certificates"

			hasAccess := rbacClusterRoleHasAccessToResource(f, clusterRole, verb, resource)
			Expect(hasAccess).Should(BeFalse())
		})

		It("should be able to get certificates", func() {
			verb := "get"
			resource := "certificates"

			hasAccess := rbacClusterRoleHasAccessToResource(f, clusterRole, verb, resource)
			Expect(hasAccess).Should(BeTrue())
		})

		It("should be able to list certificates", func() {
			verb := "list"
			resource := "certificates"

			hasAccess := rbacClusterRoleHasAccessToResource(f, clusterRole, verb, resource)
			Expect(hasAccess).Should(BeTrue())
		})

		It("should be able to watch certificates", func() {
			verb := "watch"
			resource := "certificates"

			hasAccess := rbacClusterRoleHasAccessToResource(f, clusterRole, verb, resource)
			Expect(hasAccess).Should(BeTrue())
		})
	})
	Context("with namespace edit access", func() {
		clusterRole := "edit"
		It("should be able to create certificates", func() {
			verb := "create"
			resource := "certificates"

			hasAccess := rbacClusterRoleHasAccessToResource(f, clusterRole, verb, resource)
			Expect(hasAccess).Should(BeTrue())
		})

		It("should be able to delete certificates", func() {
			verb := "delete"
			resource := "certificates"

			hasAccess := rbacClusterRoleHasAccessToResource(f, clusterRole, verb, resource)
			Expect(hasAccess).Should(BeTrue())
		})

		It("should be able to delete collections of certificates", func() {
			verb := "deletecollection"
			resource := "certificates"

			hasAccess := rbacClusterRoleHasAccessToResource(f, clusterRole, verb, resource)
			Expect(hasAccess).Should(BeTrue())
		})

		It("should be able to patch certificates", func() {
			verb := "patch"
			resource := "certificates"

			hasAccess := rbacClusterRoleHasAccessToResource(f, clusterRole, verb, resource)
			Expect(hasAccess).Should(BeTrue())
		})

		It("should be able to update certificates", func() {
			verb := "update"
			resource := "certificates"

			hasAccess := rbacClusterRoleHasAccessToResource(f, clusterRole, verb, resource)
			Expect(hasAccess).Should(BeTrue())
		})

		It("should be able to get certificates", func() {
			verb := "get"
			resource := "certificates"

			hasAccess := rbacClusterRoleHasAccessToResource(f, clusterRole, verb, resource)
			Expect(hasAccess).Should(BeTrue())
		})

		It("should be able to list certificates", func() {
			verb := "list"
			resource := "certificates"

			hasAccess := rbacClusterRoleHasAccessToResource(f, clusterRole, verb, resource)
			Expect(hasAccess).Should(BeTrue())
		})

		It("should be able to watch certificates", func() {
			verb := "watch"
			resource := "certificates"

			hasAccess := rbacClusterRoleHasAccessToResource(f, clusterRole, verb, resource)
			Expect(hasAccess).Should(BeTrue())
		})
	})

	Context("with namespace admin access", func() {
		clusterRole := "admin"
		It("should be able to create certificates", func() {
			verb := "create"
			resource := "certificates"

			hasAccess := rbacClusterRoleHasAccessToResource(f, clusterRole, verb, resource)
			Expect(hasAccess).Should(BeTrue())
		})

		It("should be able to delete certificates", func() {
			verb := "delete"
			resource := "certificates"

			hasAccess := rbacClusterRoleHasAccessToResource(f, clusterRole, verb, resource)
			Expect(hasAccess).Should(BeTrue())
		})

		It("should be able to delete collections of certificates", func() {
			verb := "deletecollection"
			resource := "certificates"

			hasAccess := rbacClusterRoleHasAccessToResource(f, clusterRole, verb, resource)
			Expect(hasAccess).Should(BeTrue())
		})

		It("should be able to patch certificates", func() {
			verb := "patch"
			resource := "certificates"

			hasAccess := rbacClusterRoleHasAccessToResource(f, clusterRole, verb, resource)
			Expect(hasAccess).Should(BeTrue())
		})

		It("should be able to update certificates", func() {
			verb := "update"
			resource := "certificates"

			hasAccess := rbacClusterRoleHasAccessToResource(f, clusterRole, verb, resource)
			Expect(hasAccess).Should(BeTrue())
		})

		It("should be able to get certificates", func() {
			verb := "get"
			resource := "certificates"

			hasAccess := rbacClusterRoleHasAccessToResource(f, clusterRole, verb, resource)
			Expect(hasAccess).Should(BeTrue())
		})

		It("should be able to list certificates", func() {
			verb := "list"
			resource := "certificates"

			hasAccess := rbacClusterRoleHasAccessToResource(f, clusterRole, verb, resource)
			Expect(hasAccess).Should(BeTrue())
		})

		It("should be able to watch certificates", func() {
			verb := "watch"
			resource := "certificates"

			hasAccess := rbacClusterRoleHasAccessToResource(f, clusterRole, verb, resource)
			Expect(hasAccess).Should(BeTrue())
		})
	})
})

{'fraction_non_alphanumeric': 0.1268777443956552, 'fraction_numerical': 0.005084354055927894, 'mean_word_length': 4.62012987012987, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2753108', 'n_tokens_mistral': 2960, 'n_tokens_neox': 2587, 'n_words': 699}