~tribaal/charms/trusty/rabbitmq-server/backport-lp1500204-with-next-tests

« back to all changes in this revision

Viewing changes to tests/deprecated/30-switch-ssl

  • Committer: Christopher Glass
  • Date: 2015-10-13 17:08:50 UTC
  • Revision ID: christopher.glass@canonical.com-20151013170850-99awo9ad2e0yu3ei
Ripped out and grafted the -next tests to the stable branch.

"Cursed, cursed creator! Why did I live?"

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python3
 
2
 
 
3
import amulet
 
4
import pika
 
5
import time
 
6
 
 
7
d = amulet.Deployment(series='trusty')
 
8
 
 
9
d.add('rabbitmq-server')
 
10
d.expose('rabbitmq-server')
 
11
 
 
12
# Don't forget to expose using d.expose(service)
 
13
 
 
14
try:
 
15
    # TODO(billy-olsen), juju test --timeout fails to pass the timeout values
 
16
    # into the environment and the charm isn't the best of places to select
 
17
    # a viable timeout since so muc is attributed to the environment anyways.
 
18
    # Need to fix this the right way, but for now we'll bump the timeout.
 
19
    d.setup(timeout=2700)
 
20
    d.sentry.wait()
 
21
except amulet.helpers.TimeoutError:
 
22
    amulet.raise_status(amulet.SKIP, msg="Environment wasn't stood up in time")
 
23
except:
 
24
    raise
 
25
 
 
26
server = d.sentry.unit['rabbitmq-server/0']
 
27
host = server.info['public-address']
 
28
 
 
29
 
 
30
# Connects without ssl
 
31
try:
 
32
    connection = pika.BlockingConnection(pika.ConnectionParameters(host=host,
 
33
                                                                   ssl=False))
 
34
except Exception as e:
 
35
    amulet.raise_status(
 
36
        amulet.FAIL,
 
37
        "Insecure connection failed with ssl=off: {}".format(str(e))
 
38
    )
 
39
 
 
40
# Doesn't connect with ssl
 
41
try:
 
42
    connection = pika.BlockingConnection(pika.ConnectionParameters(host=host,
 
43
                                                                   ssl=True))
 
44
except Exception as e:
 
45
    pass
 
46
else:
 
47
    amulet.raise_status(
 
48
        amulet.FAIL,
 
49
        'SSL enabled when it shouldn\'t.'
 
50
    )
 
51
 
 
52
d.configure('rabbitmq-server', {
 
53
    'ssl': 'on'
 
54
})
 
55
 
 
56
# There's a race for changing the configuration of a deployment.
 
57
# The configure from the juju client side happens fairly quickly, and the
 
58
# sentry.wait() can fire before the config-changed hooks do, which causes
 
59
# the wait to end... 
 
60
time.sleep(10)
 
61
d.sentry.wait()
 
62
 
 
63
# Connects without ssl
 
64
try:
 
65
    connection = pika.BlockingConnection(pika.ConnectionParameters(host=host,
 
66
                                                                   ssl=False))
 
67
except Exception as e:
 
68
    amulet.raise_status(
 
69
        amulet.FAIL,
 
70
        "Insecure connection fails with ssl=on: {}".format(str(e))
 
71
    )
 
72
 
 
73
# Connects with ssl
 
74
try:
 
75
    connection = pika.BlockingConnection(pika.ConnectionParameters(host=host,
 
76
                                                                   port=5671,
 
77
                                                                   ssl=True))
 
78
except Exception as e:
 
79
    amulet.raise_status(
 
80
        amulet.FAIL,
 
81
        "Secure connection fails with ssl=on"
 
82
    )
 
83
 
 
84
d.configure('rabbitmq-server', {
 
85
    'ssl': 'only'
 
86
})
 
87
 
 
88
# There's a race for changing the configuration of a deployment.
 
89
# The configure from the juju client side happens fairly quickly, and the
 
90
# sentry.wait() can fire before the config-changed hooks do, which causes
 
91
# the wait to end... 
 
92
time.sleep(10)
 
93
d.sentry.wait()
 
94
 
 
95
 
 
96
# Doesn't connect without ssl
 
97
try:
 
98
    connection = pika.BlockingConnection(pika.ConnectionParameters(host=host,
 
99
                                                                   ssl=False))
 
100
except Exception as e:
 
101
    pass
 
102
else:
 
103
    amulet.raise_status(
 
104
        amulet.FAIL,
 
105
        "Connects without SSL when it shouldn't"
 
106
    )
 
107
 
 
108
# Connects with ssl
 
109
try:
 
110
    connection = pika.BlockingConnection(pika.ConnectionParameters(host=host,
 
111
                                                                   port=5671,
 
112
                                                                   ssl=True))
 
113
except Exception as e:
 
114
    amulet.raise_status(
 
115
        amulet.FAIL,
 
116
        "Secure connection fails with ssl=only: {}".format(str(e))
 
117
    )