| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # coding: utf-8 | 2 # coding: utf-8 |
| 3 # Copyright 2013 The LUCI Authors. All rights reserved. | 3 # Copyright 2013 The LUCI Authors. All rights reserved. |
| 4 # Use of this source code is governed under the Apache License, Version 2.0 | 4 # Use of this source code is governed under the Apache License, Version 2.0 |
| 5 # that can be found in the LICENSE file. | 5 # that can be found in the LICENSE file. |
| 6 | 6 |
| 7 import datetime | 7 import datetime |
| 8 import itertools | 8 import itertools |
| 9 import json | 9 import json |
| 10 import logging | 10 import logging |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 r.template for r in self.app.app.router.match_routes | 455 r.template for r in self.app.app.router.match_routes |
| 456 ] | 456 ] |
| 457 | 457 |
| 458 def testCronJobTasks(self): | 458 def testCronJobTasks(self): |
| 459 # Tests all the cron tasks are securely handled. | 459 # Tests all the cron tasks are securely handled. |
| 460 cron_job_urls = [ | 460 cron_job_urls = [ |
| 461 r for r in self._GetRoutes() if r.startswith('/internal/cron/') | 461 r for r in self._GetRoutes() if r.startswith('/internal/cron/') |
| 462 ] | 462 ] |
| 463 self.assertTrue(cron_job_urls, cron_job_urls) | 463 self.assertTrue(cron_job_urls, cron_job_urls) |
| 464 | 464 |
| 465 # Stub out task queue triggered by /internal/cron/machine_provider_pubsub. | |
| 466 self.mock( | |
| 467 handlers_frontend.handlers_backend.lease_management, | |
| 468 'process_pubsub', lambda *args, **kwargs: None) | |
| 469 | |
| 470 # For ereporter. | 465 # For ereporter. |
| 471 for cron_job_url in cron_job_urls: | 466 for cron_job_url in cron_job_urls: |
| 472 self.app.get( | 467 self.app.get( |
| 473 cron_job_url, headers={'X-AppEngine-Cron': 'true'}, status=200) | 468 cron_job_url, headers={'X-AppEngine-Cron': 'true'}, status=200) |
| 474 | 469 |
| 475 # Only cron job requests can be gets for this handler. | 470 # Only cron job requests can be gets for this handler. |
| 476 response = self.app.get(cron_job_url, status=403) | 471 response = self.app.get(cron_job_url, status=403) |
| 477 self.assertEqual( | 472 self.assertEqual( |
| 478 '403 Forbidden\n\nAccess was denied to this resource.\n\n ' | 473 '403 Forbidden\n\nAccess was denied to this resource.\n\n ' |
| 479 'Only internal cron jobs can do this ', | 474 'Only internal cron jobs can do this ', |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 | 543 |
| 549 def testTaskQueueUrls(self): | 544 def testTaskQueueUrls(self): |
| 550 # Tests all the task queue tasks are securely handled. | 545 # Tests all the task queue tasks are securely handled. |
| 551 # TODO(maruel): Test mapreduce. | 546 # TODO(maruel): Test mapreduce. |
| 552 task_queue_urls = sorted( | 547 task_queue_urls = sorted( |
| 553 r for r in self._GetRoutes() if r.startswith('/internal/taskqueue/') | 548 r for r in self._GetRoutes() if r.startswith('/internal/taskqueue/') |
| 554 if r != '/internal/taskqueue/mapreduce/launch/<job_id:[^\\/]+>' | 549 if r != '/internal/taskqueue/mapreduce/launch/<job_id:[^\\/]+>' |
| 555 ) | 550 ) |
| 556 task_queues = [ | 551 task_queues = [ |
| 557 ('cleanup', '/internal/taskqueue/cleanup_data'), | 552 ('cleanup', '/internal/taskqueue/cleanup_data'), |
| 558 ('machine-provider-pubsub', | 553 ('machine-provider-manage', |
| 559 '/internal/taskqueue/pubsub/machine_provider'), | 554 '/internal/taskqueue/machine-provider-manage'), |
| 560 ('pubsub', '/internal/taskqueue/pubsub/<task_id:[0-9a-f]+>'), | 555 ('pubsub', '/internal/taskqueue/pubsub/<task_id:[0-9a-f]+>'), |
| 561 ] | 556 ] |
| 562 self.assertEqual(sorted(zip(*task_queues)[1]), task_queue_urls) | 557 self.assertEqual(sorted(zip(*task_queues)[1]), task_queue_urls) |
| 563 | 558 |
| 564 for _, url in task_queues: | 559 for _, url in task_queues: |
| 565 url = url.replace('<task_id:[0-9a-f]+>', 'abcabcabc') | 560 url = url.replace('<task_id:[0-9a-f]+>', 'abcabcabc') |
| 566 self.app.post( | 561 self.app.post( |
| 567 url, headers={'X-AppEngine-QueueName': 'bogus name'}, status=403) | 562 url, headers={'X-AppEngine-QueueName': 'bogus name'}, status=403) |
| 568 | 563 |
| 569 | 564 |
| 570 if __name__ == '__main__': | 565 if __name__ == '__main__': |
| 571 if '-v' in sys.argv: | 566 if '-v' in sys.argv: |
| 572 unittest.TestCase.maxDiff = None | 567 unittest.TestCase.maxDiff = None |
| 573 logging.basicConfig( | 568 logging.basicConfig( |
| 574 level=logging.DEBUG if '-v' in sys.argv else logging.CRITICAL, | 569 level=logging.DEBUG if '-v' in sys.argv else logging.CRITICAL, |
| 575 format='%(levelname)-7s %(filename)s:%(lineno)3d %(message)s') | 570 format='%(levelname)-7s %(filename)s:%(lineno)3d %(message)s') |
| 576 unittest.main() | 571 unittest.main() |
| OLD | NEW |