James E. Blair | 59fdbac | 2015-12-07 17:08:06 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | # Copyright 2012 Hewlett-Packard Development Company, L.P. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | # not use this file except in compliance with the License. You may obtain |
| 7 | # a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | # License for the specific language governing permissions and limitations |
| 15 | # under the License. |
| 16 | |
James E. Blair | a92cbc8 | 2017-01-23 14:56:49 -0800 | [diff] [blame] | 17 | import os |
James E. Blair | 14abdf4 | 2015-12-09 16:11:53 -0800 | [diff] [blame] | 18 | import textwrap |
James E. Blair | 59fdbac | 2015-12-07 17:08:06 -0800 | [diff] [blame] | 19 | |
James E. Blair | b9c0d77 | 2017-03-03 14:34:49 -0800 | [diff] [blame] | 20 | import testtools |
| 21 | |
| 22 | import zuul.configloader |
James E. Blair | bf1a4f2 | 2017-03-17 10:59:37 -0700 | [diff] [blame] | 23 | from zuul.lib import encryption |
Ricardo Carrillo Cruz | 22994f9 | 2016-12-02 11:41:58 +0000 | [diff] [blame] | 24 | from tests.base import AnsibleZuulTestCase, ZuulTestCase, FIXTURE_DIR |
James E. Blair | 59fdbac | 2015-12-07 17:08:06 -0800 | [diff] [blame] | 25 | |
James E. Blair | 59fdbac | 2015-12-07 17:08:06 -0800 | [diff] [blame] | 26 | |
James E. Blair | 3f876d5 | 2016-07-22 13:07:14 -0700 | [diff] [blame] | 27 | class TestMultipleTenants(AnsibleZuulTestCase): |
James E. Blair | 59fdbac | 2015-12-07 17:08:06 -0800 | [diff] [blame] | 28 | # A temporary class to hold new tests while others are disabled |
| 29 | |
James E. Blair | 2a629ec | 2015-12-22 15:32:02 -0800 | [diff] [blame] | 30 | tenant_config_file = 'config/multi-tenant/main.yaml' |
James E. Blair | 59fdbac | 2015-12-07 17:08:06 -0800 | [diff] [blame] | 31 | |
James E. Blair | 8300578 | 2015-12-11 14:46:03 -0800 | [diff] [blame] | 32 | def test_multiple_tenants(self): |
James E. Blair | 96f2694 | 2015-12-09 10:15:59 -0800 | [diff] [blame] | 33 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 34 | A.addApproval('code-review', 2) |
| 35 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 59fdbac | 2015-12-07 17:08:06 -0800 | [diff] [blame] | 36 | self.waitUntilSettled() |
James E. Blair | 96f2694 | 2015-12-09 10:15:59 -0800 | [diff] [blame] | 37 | self.assertEqual(self.getJobFromHistory('project1-test1').result, |
James E. Blair | 59fdbac | 2015-12-07 17:08:06 -0800 | [diff] [blame] | 38 | 'SUCCESS') |
James E. Blair | 96c6bf8 | 2016-01-15 16:20:40 -0800 | [diff] [blame] | 39 | self.assertEqual(self.getJobFromHistory('python27').result, |
| 40 | 'SUCCESS') |
James E. Blair | 59fdbac | 2015-12-07 17:08:06 -0800 | [diff] [blame] | 41 | self.assertEqual(A.data['status'], 'MERGED') |
James E. Blair | 96f2694 | 2015-12-09 10:15:59 -0800 | [diff] [blame] | 42 | self.assertEqual(A.reported, 2, |
| 43 | "A should report start and success") |
| 44 | self.assertIn('tenant-one-gate', A.messages[1], |
| 45 | "A should transit tenant-one gate") |
| 46 | self.assertNotIn('tenant-two-gate', A.messages[1], |
| 47 | "A should *not* transit tenant-two gate") |
James E. Blair | 59fdbac | 2015-12-07 17:08:06 -0800 | [diff] [blame] | 48 | |
James E. Blair | 96f2694 | 2015-12-09 10:15:59 -0800 | [diff] [blame] | 49 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 50 | B.addApproval('code-review', 2) |
| 51 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 96f2694 | 2015-12-09 10:15:59 -0800 | [diff] [blame] | 52 | self.waitUntilSettled() |
James E. Blair | 96c6bf8 | 2016-01-15 16:20:40 -0800 | [diff] [blame] | 53 | self.assertEqual(self.getJobFromHistory('python27', |
| 54 | 'org/project2').result, |
| 55 | 'SUCCESS') |
James E. Blair | 96f2694 | 2015-12-09 10:15:59 -0800 | [diff] [blame] | 56 | self.assertEqual(self.getJobFromHistory('project2-test1').result, |
| 57 | 'SUCCESS') |
| 58 | self.assertEqual(B.data['status'], 'MERGED') |
| 59 | self.assertEqual(B.reported, 2, |
| 60 | "B should report start and success") |
| 61 | self.assertIn('tenant-two-gate', B.messages[1], |
| 62 | "B should transit tenant-two gate") |
| 63 | self.assertNotIn('tenant-one-gate', B.messages[1], |
| 64 | "B should *not* transit tenant-one gate") |
James E. Blair | 59fdbac | 2015-12-07 17:08:06 -0800 | [diff] [blame] | 65 | |
James E. Blair | 96f2694 | 2015-12-09 10:15:59 -0800 | [diff] [blame] | 66 | self.assertEqual(A.reported, 2, "Activity in tenant two should" |
| 67 | "not affect tenant one") |
James E. Blair | 14abdf4 | 2015-12-09 16:11:53 -0800 | [diff] [blame] | 68 | |
James E. Blair | 8300578 | 2015-12-11 14:46:03 -0800 | [diff] [blame] | 69 | |
James E. Blair | ff55574 | 2017-02-19 11:34:27 -0800 | [diff] [blame] | 70 | class TestInRepoConfig(ZuulTestCase): |
James E. Blair | 8300578 | 2015-12-11 14:46:03 -0800 | [diff] [blame] | 71 | # A temporary class to hold new tests while others are disabled |
| 72 | |
James E. Blair | 2a629ec | 2015-12-22 15:32:02 -0800 | [diff] [blame] | 73 | tenant_config_file = 'config/in-repo/main.yaml' |
James E. Blair | 8300578 | 2015-12-11 14:46:03 -0800 | [diff] [blame] | 74 | |
James E. Blair | 8300578 | 2015-12-11 14:46:03 -0800 | [diff] [blame] | 75 | def test_in_repo_config(self): |
James E. Blair | 14abdf4 | 2015-12-09 16:11:53 -0800 | [diff] [blame] | 76 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 77 | A.addApproval('code-review', 2) |
| 78 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 14abdf4 | 2015-12-09 16:11:53 -0800 | [diff] [blame] | 79 | self.waitUntilSettled() |
| 80 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 81 | 'SUCCESS') |
| 82 | self.assertEqual(A.data['status'], 'MERGED') |
| 83 | self.assertEqual(A.reported, 2, |
| 84 | "A should report start and success") |
| 85 | self.assertIn('tenant-one-gate', A.messages[1], |
| 86 | "A should transit tenant-one gate") |
James E. Blair | b97ed80 | 2015-12-21 15:55:35 -0800 | [diff] [blame] | 87 | |
James E. Blair | 8b1dc3f | 2016-07-05 16:49:00 -0700 | [diff] [blame] | 88 | def test_dynamic_config(self): |
| 89 | in_repo_conf = textwrap.dedent( |
| 90 | """ |
| 91 | - job: |
| 92 | name: project-test2 |
| 93 | |
| 94 | - project: |
| 95 | name: org/project |
| 96 | tenant-one-gate: |
| 97 | jobs: |
| 98 | - project-test2 |
| 99 | """) |
| 100 | |
James E. Blair | c73c73a | 2017-01-20 15:15:15 -0800 | [diff] [blame] | 101 | in_repo_playbook = textwrap.dedent( |
| 102 | """ |
| 103 | - hosts: all |
| 104 | tasks: [] |
| 105 | """) |
| 106 | |
| 107 | file_dict = {'.zuul.yaml': in_repo_conf, |
| 108 | 'playbooks/project-test2.yaml': in_repo_playbook} |
James E. Blair | 8b1dc3f | 2016-07-05 16:49:00 -0700 | [diff] [blame] | 109 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A', |
James E. Blair | c73c73a | 2017-01-20 15:15:15 -0800 | [diff] [blame] | 110 | files=file_dict) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 111 | A.addApproval('code-review', 2) |
| 112 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8b1dc3f | 2016-07-05 16:49:00 -0700 | [diff] [blame] | 113 | self.waitUntilSettled() |
James E. Blair | 8b1dc3f | 2016-07-05 16:49:00 -0700 | [diff] [blame] | 114 | self.assertEqual(A.data['status'], 'MERGED') |
| 115 | self.assertEqual(A.reported, 2, |
| 116 | "A should report start and success") |
| 117 | self.assertIn('tenant-one-gate', A.messages[1], |
| 118 | "A should transit tenant-one gate") |
James E. Blair | 646322f | 2017-01-27 15:50:34 -0800 | [diff] [blame] | 119 | self.assertHistory([ |
| 120 | dict(name='project-test2', result='SUCCESS', changes='1,1')]) |
| 121 | |
James E. Blair | c2a5ed7 | 2017-02-20 14:12:01 -0500 | [diff] [blame] | 122 | self.fake_gerrit.addEvent(A.getChangeMergedEvent()) |
James E. Blair | 7bbd7a3 | 2017-03-06 11:36:13 -0800 | [diff] [blame] | 123 | self.waitUntilSettled() |
James E. Blair | c2a5ed7 | 2017-02-20 14:12:01 -0500 | [diff] [blame] | 124 | |
James E. Blair | 646322f | 2017-01-27 15:50:34 -0800 | [diff] [blame] | 125 | # Now that the config change is landed, it should be live for |
| 126 | # subsequent changes. |
| 127 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 128 | B.addApproval('code-review', 2) |
| 129 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 130 | self.waitUntilSettled() |
| 131 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 132 | 'SUCCESS') |
| 133 | self.assertHistory([ |
| 134 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 135 | dict(name='project-test2', result='SUCCESS', changes='2,1')]) |
James E. Blair | c73c73a | 2017-01-20 15:15:15 -0800 | [diff] [blame] | 136 | |
James E. Blair | ff55574 | 2017-02-19 11:34:27 -0800 | [diff] [blame] | 137 | def test_in_repo_branch(self): |
| 138 | in_repo_conf = textwrap.dedent( |
| 139 | """ |
| 140 | - job: |
| 141 | name: project-test2 |
| 142 | |
| 143 | - project: |
| 144 | name: org/project |
| 145 | tenant-one-gate: |
| 146 | jobs: |
| 147 | - project-test2 |
| 148 | """) |
| 149 | |
| 150 | in_repo_playbook = textwrap.dedent( |
| 151 | """ |
| 152 | - hosts: all |
| 153 | tasks: [] |
| 154 | """) |
| 155 | |
| 156 | file_dict = {'.zuul.yaml': in_repo_conf, |
| 157 | 'playbooks/project-test2.yaml': in_repo_playbook} |
| 158 | self.create_branch('org/project', 'stable') |
| 159 | A = self.fake_gerrit.addFakeChange('org/project', 'stable', 'A', |
| 160 | files=file_dict) |
| 161 | A.addApproval('code-review', 2) |
| 162 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 163 | self.waitUntilSettled() |
| 164 | self.assertEqual(A.data['status'], 'MERGED') |
| 165 | self.assertEqual(A.reported, 2, |
| 166 | "A should report start and success") |
| 167 | self.assertIn('tenant-one-gate', A.messages[1], |
| 168 | "A should transit tenant-one gate") |
| 169 | self.assertHistory([ |
| 170 | dict(name='project-test2', result='SUCCESS', changes='1,1')]) |
| 171 | self.fake_gerrit.addEvent(A.getChangeMergedEvent()) |
James E. Blair | 7bbd7a3 | 2017-03-06 11:36:13 -0800 | [diff] [blame] | 172 | self.waitUntilSettled() |
James E. Blair | ff55574 | 2017-02-19 11:34:27 -0800 | [diff] [blame] | 173 | |
| 174 | # The config change should not affect master. |
| 175 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 176 | B.addApproval('code-review', 2) |
| 177 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 178 | self.waitUntilSettled() |
| 179 | self.assertHistory([ |
| 180 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 181 | dict(name='project-test1', result='SUCCESS', changes='2,1')]) |
| 182 | |
| 183 | # The config change should be live for further changes on |
| 184 | # stable. |
| 185 | C = self.fake_gerrit.addFakeChange('org/project', 'stable', 'C') |
| 186 | C.addApproval('code-review', 2) |
| 187 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 188 | self.waitUntilSettled() |
| 189 | self.assertHistory([ |
| 190 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 191 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 192 | dict(name='project-test2', result='SUCCESS', changes='3,1')]) |
| 193 | |
James E. Blair | a5a1249 | 2017-05-03 11:40:48 -0700 | [diff] [blame^] | 194 | def test_crd_dynamic_config_branch(self): |
| 195 | # Test that we can create a job in one repo and be able to use |
| 196 | # it from a different branch on a different repo. |
| 197 | |
| 198 | self.create_branch('org/project1', 'stable') |
| 199 | |
| 200 | in_repo_conf = textwrap.dedent( |
| 201 | """ |
| 202 | - job: |
| 203 | name: project-test2 |
| 204 | |
| 205 | - project: |
| 206 | name: org/project |
| 207 | check: |
| 208 | jobs: |
| 209 | - project-test2 |
| 210 | """) |
| 211 | |
| 212 | in_repo_playbook = textwrap.dedent( |
| 213 | """ |
| 214 | - hosts: all |
| 215 | tasks: [] |
| 216 | """) |
| 217 | |
| 218 | file_dict = {'.zuul.yaml': in_repo_conf, |
| 219 | 'playbooks/project-test2.yaml': in_repo_playbook} |
| 220 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A', |
| 221 | files=file_dict) |
| 222 | |
| 223 | second_repo_conf = textwrap.dedent( |
| 224 | """ |
| 225 | - project: |
| 226 | name: org/project1 |
| 227 | check: |
| 228 | jobs: |
| 229 | - project-test2 |
| 230 | """) |
| 231 | |
| 232 | second_file_dict = {'.zuul.yaml': second_repo_conf} |
| 233 | B = self.fake_gerrit.addFakeChange('org/project1', 'stable', 'B', |
| 234 | files=second_file_dict) |
| 235 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 236 | B.subject, A.data['id']) |
| 237 | |
| 238 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 239 | self.waitUntilSettled() |
| 240 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 241 | self.waitUntilSettled() |
| 242 | |
| 243 | self.assertEqual(A.reported, 1, "A should report") |
| 244 | self.assertHistory([ |
| 245 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 246 | dict(name='project-test2', result='SUCCESS', changes='1,1 2,1'), |
| 247 | ]) |
| 248 | |
James E. Blair | 149b69c | 2017-03-02 10:48:16 -0800 | [diff] [blame] | 249 | def test_untrusted_syntax_error(self): |
James E. Blair | e53250c | 2017-03-01 14:34:36 -0800 | [diff] [blame] | 250 | in_repo_conf = textwrap.dedent( |
| 251 | """ |
| 252 | - job: |
| 253 | name: project-test2 |
| 254 | foo: error |
| 255 | """) |
| 256 | |
| 257 | file_dict = {'.zuul.yaml': in_repo_conf} |
| 258 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A', |
| 259 | files=file_dict) |
| 260 | A.addApproval('code-review', 2) |
| 261 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 262 | self.waitUntilSettled() |
| 263 | |
| 264 | self.assertEqual(A.data['status'], 'NEW') |
| 265 | self.assertEqual(A.reported, 2, |
| 266 | "A should report start and failure") |
| 267 | self.assertIn('syntax error', A.messages[1], |
| 268 | "A should have a syntax error reported") |
| 269 | |
James E. Blair | 149b69c | 2017-03-02 10:48:16 -0800 | [diff] [blame] | 270 | def test_trusted_syntax_error(self): |
| 271 | in_repo_conf = textwrap.dedent( |
| 272 | """ |
| 273 | - job: |
| 274 | name: project-test2 |
| 275 | foo: error |
| 276 | """) |
| 277 | |
| 278 | file_dict = {'zuul.yaml': in_repo_conf} |
| 279 | A = self.fake_gerrit.addFakeChange('common-config', 'master', 'A', |
| 280 | files=file_dict) |
| 281 | A.addApproval('code-review', 2) |
| 282 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 283 | self.waitUntilSettled() |
| 284 | |
| 285 | self.assertEqual(A.data['status'], 'NEW') |
| 286 | self.assertEqual(A.reported, 2, |
| 287 | "A should report start and failure") |
| 288 | self.assertIn('syntax error', A.messages[1], |
| 289 | "A should have a syntax error reported") |
| 290 | |
James E. Blair | 6f140c7 | 2017-03-03 10:32:07 -0800 | [diff] [blame] | 291 | def test_untrusted_yaml_error(self): |
| 292 | in_repo_conf = textwrap.dedent( |
| 293 | """ |
| 294 | - job: |
| 295 | foo: error |
| 296 | """) |
| 297 | |
| 298 | file_dict = {'.zuul.yaml': in_repo_conf} |
| 299 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A', |
| 300 | files=file_dict) |
| 301 | A.addApproval('code-review', 2) |
| 302 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 303 | self.waitUntilSettled() |
| 304 | |
| 305 | self.assertEqual(A.data['status'], 'NEW') |
| 306 | self.assertEqual(A.reported, 2, |
| 307 | "A should report start and failure") |
| 308 | self.assertIn('syntax error', A.messages[1], |
| 309 | "A should have a syntax error reported") |
| 310 | |
James E. Blair | c73c73a | 2017-01-20 15:15:15 -0800 | [diff] [blame] | 311 | |
| 312 | class TestAnsible(AnsibleZuulTestCase): |
| 313 | # A temporary class to hold new tests while others are disabled |
| 314 | |
| 315 | tenant_config_file = 'config/ansible/main.yaml' |
| 316 | |
| 317 | def test_playbook(self): |
| 318 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 319 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 320 | self.waitUntilSettled() |
Paul Belanger | 96618ed | 2017-03-01 09:42:33 -0500 | [diff] [blame] | 321 | build = self.getJobFromHistory('timeout') |
Clark Boylan | 53fb126 | 2017-04-25 08:37:56 -0700 | [diff] [blame] | 322 | self.assertEqual(build.result, 'TIMED_OUT') |
Monty Taylor | c231d93 | 2017-02-03 09:57:15 -0600 | [diff] [blame] | 323 | build = self.getJobFromHistory('faillocal') |
| 324 | self.assertEqual(build.result, 'FAILURE') |
Paul Belanger | e2b8d49 | 2017-03-22 18:57:40 -0400 | [diff] [blame] | 325 | build = self.getJobFromHistory('check-vars') |
Paul Belanger | 30ba93a | 2017-03-16 16:28:10 -0400 | [diff] [blame] | 326 | self.assertEqual(build.result, 'SUCCESS') |
James E. Blair | a92cbc8 | 2017-01-23 14:56:49 -0800 | [diff] [blame] | 327 | build = self.getJobFromHistory('python27') |
| 328 | self.assertEqual(build.result, 'SUCCESS') |
| 329 | flag_path = os.path.join(self.test_root, build.uuid + '.flag') |
| 330 | self.assertTrue(os.path.exists(flag_path)) |
Monty Taylor | c231d93 | 2017-02-03 09:57:15 -0600 | [diff] [blame] | 331 | copied_path = os.path.join(self.test_root, build.uuid + |
| 332 | '.copied') |
| 333 | self.assertTrue(os.path.exists(copied_path)) |
| 334 | failed_path = os.path.join(self.test_root, build.uuid + |
| 335 | '.failed') |
| 336 | self.assertFalse(os.path.exists(failed_path)) |
James E. Blair | 66b274e | 2017-01-31 14:47:52 -0800 | [diff] [blame] | 337 | pre_flag_path = os.path.join(self.test_root, build.uuid + |
| 338 | '.pre.flag') |
| 339 | self.assertTrue(os.path.exists(pre_flag_path)) |
| 340 | post_flag_path = os.path.join(self.test_root, build.uuid + |
| 341 | '.post.flag') |
| 342 | self.assertTrue(os.path.exists(post_flag_path)) |
James E. Blair | 5ac9384 | 2017-01-20 06:47:34 -0800 | [diff] [blame] | 343 | bare_role_flag_path = os.path.join(self.test_root, |
| 344 | build.uuid + '.bare-role.flag') |
| 345 | self.assertTrue(os.path.exists(bare_role_flag_path)) |
James E. Blair | b9c0d77 | 2017-03-03 14:34:49 -0800 | [diff] [blame] | 346 | |
James E. Blair | 18f86a3 | 2017-03-15 14:43:26 -0700 | [diff] [blame] | 347 | secrets_path = os.path.join(self.test_root, |
| 348 | build.uuid + '.secrets') |
| 349 | with open(secrets_path) as f: |
| 350 | self.assertEqual(f.read(), "test-username test-password") |
| 351 | |
James E. Blair | b9c0d77 | 2017-03-03 14:34:49 -0800 | [diff] [blame] | 352 | |
| 353 | class TestBrokenConfig(ZuulTestCase): |
| 354 | # Test that we get an appropriate syntax error if we start with a |
| 355 | # broken config. |
| 356 | |
| 357 | tenant_config_file = 'config/broken/main.yaml' |
| 358 | |
| 359 | def setUp(self): |
| 360 | with testtools.ExpectedException( |
| 361 | zuul.configloader.ConfigurationSyntaxError, |
| 362 | "\nZuul encountered a syntax error"): |
| 363 | super(TestBrokenConfig, self).setUp() |
| 364 | |
| 365 | def test_broken_config_on_startup(self): |
| 366 | pass |
Ricardo Carrillo Cruz | 22994f9 | 2016-12-02 11:41:58 +0000 | [diff] [blame] | 367 | |
| 368 | |
| 369 | class TestProjectKeys(ZuulTestCase): |
| 370 | # Test that we can generate project keys |
| 371 | |
| 372 | # Normally the test infrastructure copies a static key in place |
| 373 | # for each project before starting tests. This saves time because |
| 374 | # Zuul's automatic key-generation on startup can be slow. To make |
| 375 | # sure we exercise that code, in this test we allow Zuul to create |
| 376 | # keys for the project on startup. |
| 377 | create_project_keys = True |
| 378 | tenant_config_file = 'config/in-repo/main.yaml' |
| 379 | |
| 380 | def test_key_generation(self): |
| 381 | key_root = os.path.join(self.state_root, 'keys') |
| 382 | private_key_file = os.path.join(key_root, 'gerrit/org/project.pem') |
| 383 | # Make sure that a proper key was created on startup |
| 384 | with open(private_key_file, "rb") as f: |
James E. Blair | bf1a4f2 | 2017-03-17 10:59:37 -0700 | [diff] [blame] | 385 | private_key, public_key = \ |
| 386 | encryption.deserialize_rsa_keypair(f.read()) |
Ricardo Carrillo Cruz | 22994f9 | 2016-12-02 11:41:58 +0000 | [diff] [blame] | 387 | |
| 388 | with open(os.path.join(FIXTURE_DIR, 'private.pem')) as i: |
| 389 | fixture_private_key = i.read() |
| 390 | |
| 391 | # Make sure that we didn't just end up with the static fixture |
| 392 | # key |
| 393 | self.assertNotEqual(fixture_private_key, private_key) |
| 394 | |
| 395 | # Make sure it's the right length |
| 396 | self.assertEqual(4096, private_key.key_size) |