Skip to content

Commit

Permalink
Merge pull request rancher#24477 from XianglongLuo/notifiersmtp
Browse files Browse the repository at this point in the history
Test for setting email notifier SMTP password
  • Loading branch information
dramich committed Feb 20, 2020
2 parents e11d478 + 038e65d commit f0b6ed4
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -83,7 +83,7 @@ require (
github.com/rancher/rke v1.1.0-rc6
github.com/rancher/security-scan v0.1.5
github.com/rancher/steve v0.0.0-20200214232004-4218314653de
github.com/rancher/types v0.0.0-20200218191331-dc762fc27c91
github.com/rancher/types v0.0.0-20200219204417-26b7145e8f0a
github.com/rancher/wrangler v0.4.2-0.20200215064225-8abf292acf7b
github.com/rancher/wrangler-api v0.4.1
github.com/robfig/cron v1.1.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Expand Up @@ -837,6 +837,8 @@ github.com/rancher/types v0.0.0-20200123224322-9adcafc483ee h1:kYxNoRYCC9wP72ou8
github.com/rancher/types v0.0.0-20200123224322-9adcafc483ee/go.mod h1:rN9IgDRV1O4HTJCLtpLqyUEfdPsoeBoH2wNUm8PPThk=
github.com/rancher/types v0.0.0-20200218191331-dc762fc27c91 h1:IitaXkx6eqd4nCQMzJkGriaNWk/kDKfO5CasK3AXhp4=
github.com/rancher/types v0.0.0-20200218191331-dc762fc27c91/go.mod h1:7v/f4VGMfBQi5yQQxlFHylW6QP4w6vCxd6KKPG5sZpM=
github.com/rancher/types v0.0.0-20200219204417-26b7145e8f0a h1:TMC1ZXqVK4uCyN/RGHGN+NFGefWhkZo07VhYb+Sctbo=
github.com/rancher/types v0.0.0-20200219204417-26b7145e8f0a/go.mod h1:7v/f4VGMfBQi5yQQxlFHylW6QP4w6vCxd6KKPG5sZpM=
github.com/rancher/wrangler v0.1.4/go.mod h1:EYP7cqpg42YqElaCm+U9ieSrGQKAXxUH5xsr+XGpWyE=
github.com/rancher/wrangler v0.4.0/go.mod h1:1cR91WLhZgkZ+U4fV9nVuXqKurWbgXcIReU4wnQvTN8=
github.com/rancher/wrangler v0.4.1 h1:kQLE6syPbX4ciwU4OF+EHIPT9zj6r6pyN83u9Gsv5eg=
Expand Down
62 changes: 62 additions & 0 deletions tests/integration/suite/test_notifier.py
@@ -0,0 +1,62 @@
from kubernetes.client import CustomObjectsApi
from .common import random_str


def test_notifier_smtp_password(admin_mc, remove_resource):
client = admin_mc.client
name = random_str()
password = random_str()
notifier = client.create_notifier(clusterId="local",
name=name,
smtpConfig={
"defaultRecipient": "test",
"host": "test",
"port": "587",
"sender": "test",
"tls": "true",
"username": "test",
"password": password
})
remove_resource(notifier)
assert notifier is not None

# Test password not present in api
assert notifier['smtpConfig'].get('password') is None

crd_client = get_crd_client(admin_mc)
ns, name = notifier["id"].split(":")
# Test password is in k8s after creation
verify_smtp_password(crd_client, ns, name, password)
# Test noop, password field should be as it is
notifier = client.update(notifier, smtpConfig=notifier['smtpConfig'])
verify_smtp_password(crd_client, ns, name, password)
# Test updating password
new_password = random_str()
notifier = client.update(notifier, smtpConfig={
"password": new_password})
verify_smtp_password(crd_client, ns, name, new_password)
# Test updating field non-password related
notifier = client.update(notifier, smtpConfig={"username": "test2"})
notifier = client.reload(notifier)
assert notifier["smtpConfig"]["username"] == "test2"
# Test the password in crd remains the same value after updating username
verify_smtp_password(crd_client, ns, name, new_password)


def verify_smtp_password(crd_client, ns, name, password):
crd_dict = {
'group': 'management.cattle.io',
'version': 'v3',
'namespace': 'local',
'plural': 'notifiers',
'name': name,
}

k8s_notifier = crd_client.get_namespaced_custom_object(**crd_dict)
smtp_password = k8s_notifier['spec']['smtpConfig']['password']

assert smtp_password == password


def get_crd_client(admin_mc):
return CustomObjectsApi(admin_mc.k8s_client)

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Expand Up @@ -453,7 +453,7 @@ github.com/rancher/steve/pkg/server/resources/common
github.com/rancher/steve/pkg/server/resources/counts
github.com/rancher/steve/pkg/server/router
github.com/rancher/steve/pkg/server/store/proxy
# github.com/rancher/types v0.0.0-20200218191331-dc762fc27c91
# github.com/rancher/types v0.0.0-20200219204417-26b7145e8f0a
github.com/rancher/types/apis/apiregistration.k8s.io/v1
github.com/rancher/types/apis/apps/v1
github.com/rancher/types/apis/autoscaling/v2beta2
Expand Down

0 comments on commit f0b6ed4

Please sign in to comment.