Ejemplo n.º 1
0
    def testInvalidContentPulled(self):
        subscription = """
subscriptions: {
  name: "Missing Email"
  bug_labels: ["Some-Label"]
  bug_components: ["Some>Component"]
  patterns: [{glob: "project/**"}]
}"""
        invalid_content = """
{
  "configs": [
    {
      "url": "https://example.com/p/s/+/0123456789abcde/chromeperf-sheriff.cfg",
      "content": "%s",
      "content_hash": "v1:somehash",
      "config_set": "projects/project",
      "revision": "0123456789abcdef"
    }
  ]
}""" % (base64.standard_b64encode(bytearray(subscription, 'utf-8')).decode(), )
        app = service.CreateApp({
            'environ': {
                'GOOGLE_CLOUD_PROJECT': 'chromeperf',
                'GAE_SERVICE': 'sheriff-config',
            },
            'datastore_client':
            datastore.Client(credentials=credentials.AnonymousCredentials(),
                             project='chromeperf'),
            'http':
            HttpMockSequenceWithDiscovery([({
                'status': '200'
            }, invalid_content), ({
                'status': '200'
            }, self.sample_config), ({
                'status': '200'
            }, invalid_content)]),
        })
        client = app.test_client()

        # Step 1: Get an invalid config.
        response = client.get('/configs/update',
                              headers={'X-Forwarded-Proto': 'https'})
        self.assertEqual(response.status_code, 500)

        # Step 2: Get a config that's valid.
        response = client.get('/configs/update',
                              headers={'X-Forwarded-Proto': 'https'})
        self.assertEqual(response.status_code, 200)

        self.AssertProjectConfigSet1Holds(client, 200)
        self.AssertProjectConfigSet2Holds(client, 200)

        # Step 3: Get a config that's invalid, but ensure that the valid config
        # holds.
        response = client.get('/configs/update',
                              headers={'X-Forwarded-Proto': 'https'})
        self.assertEqual(response.status_code, 500)
        self.AssertProjectConfigSet1Holds(client, 200)
        self.AssertProjectConfigSet2Holds(client, 200)
Ejemplo n.º 2
0
 def setUp(self):
     self.app = service.CreateApp({
         'environ': {
             'GOOGLE_CLOUD_PROJECT': 'chromeperf',
             'GAE_SERVICE': 'sheriff-config'
         },
         'http': HttpMockSequenceWithDiscovery([])
     })
     self.client = self.app.test_client()
Ejemplo n.º 3
0
 def setUp(self):
     with open('tests/config-discovery.json') as discovery_file:
         self.app = service.CreateApp({
             'environ': {
                 'GOOGLE_CLOUD_PROJECT': 'chromeperf',
                 'GAE_SERVICE': 'sheriff-config'
             },
             'http':
             HttpMockSequence([({
                 'status': '200'
             }, discovery_file.read())])
         })
     self.client = self.app.test_client()
Ejemplo n.º 4
0
 def setUp(self):
     with open('tests/sample-configs-get_project_configs.json'
               ) as sample_config_file:
         self.sample_config = sample_config_file.read()
     self.app = service.CreateApp({
         'environ': {
             'GOOGLE_CLOUD_PROJECT': 'chromeperf',
             'GAE_SERVICE': 'sheriff-config',
         },
         'datastore_client':
         datastore.Client(credentials=credentials.AnonymousCredentials(),
                          project='chromeperf'),
         'http':
         HttpMockSequenceWithDiscovery([({
             'status': '200'
         }, self.sample_config)]),
     })
Ejemplo n.º 5
0
 def testPollAndEmptyConfigs(self):
     app = service.CreateApp({
         'environ': {
             'GOOGLE_CLOUD_PROJECT': 'chromeperf',
             'GAE_SERVICE': 'sheriff-config',
         },
         'datastore_client':
         datastore.Client(credentials=credentials.AnonymousCredentials(),
                          project='chromeperf'),
         'http':
         HttpMockSequenceWithDiscovery([({
             'status': '200'
         }, '{}')])
     })
     client = app.test_client()
     response = client.get('/configs/update',
                           headers={'X-Forwarded-Proto': 'https'})
     self.assertEqual(response.status_code, 200)
Ejemplo n.º 6
0
    def testPollConfigAddsAndRemoves(self):
        with open('tests/sample-configs-get_project_configs_reduced.json'
                  ) as sample_config_file:
            sample_config_reduced = sample_config_file.read()
        app = service.CreateApp({
            'environ': {
                'GOOGLE_CLOUD_PROJECT': 'chromeperf',
                'GAE_SERVICE': 'sheriff-config',
            },
            'datastore_client':
            datastore.Client(credentials=credentials.AnonymousCredentials(),
                             project='chromeperf'),
            'http':
            HttpMockSequenceWithDiscovery([({
                'status': '200'
            }, self.sample_config), ({
                'status': '200'
            }, sample_config_reduced)]),
        })

        # Step 1: Get one configuration with two config sets.
        client = app.test_client()
        response = client.get('/configs/update',
                              headers={'X-Forwarded-Proto': 'https'})
        self.assertEqual(response.status_code, 200)

        self.AssertProjectConfigSet1Holds(client, 200)
        self.AssertProjectConfigSet2Holds(client, 200)

        # Step 2: Get another configuration, this time with just one config set.
        response = client.get('/configs/update',
                              headers={'X-Forwarded-Proto': 'https'})
        self.assertEqual(response.status_code, 200)

        # Update doesn't take effect because of caching
        self.AssertProjectConfigSet1Holds(client, 200)
        self.AssertProjectConfigSet2Holds(client, 200)

        # mocking utils.Time to invalid caching
        with mock.patch('utils.Time') as mock_time:
            mock_time.method.return_value = (time.time() + 60)
            self.AssertProjectConfigSet1Holds(client, 404)
            self.AssertProjectConfigSet2Holds(client, 200)
Ejemplo n.º 7
0
# Copyright 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Sheriff Config Service

This service implements the requirements for supporting sheriff configuration
file validation.
"""
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
import service

APP = service.CreateApp()
Ejemplo n.º 8
0
 def testListSubscriptions(self):
     app = service.CreateApp({
         'environ': {
             'GOOGLE_CLOUD_PROJECT': 'chromeperf',
             'GAE_SERVICE': 'sheriff-config',
         },
         'datastore_client':
         datastore.Client(credentials=credentials.AnonymousCredentials(),
                          project='chromeperf'),
         'http':
         HttpMockSequenceWithDiscovery([({
             'status': '200'
         }, self.sample_config), ({
             'status': '200'
         }, '{ "is_member": true }'),
                                        ({
                                            'status': '200'
                                        }, '{ "is_member": false }')]),
     })
     client = app.test_client()
     response = client.get('/configs/update',
                           headers={'X-Forwarded-Proto': 'https'})
     self.assertEqual(response.status_code, 200)
     response = client.post('/subscriptions/list',
                            json={'identity_email': '*****@*****.**'},
                            headers={'X-Forwarded-Proto': 'https'})
     self.assertEqual(response.status_code, 200)
     self.assertDictEqual(
         response.get_json(), {
             'subscriptions': [{
                 'config_set': 'projects/project',
                 'revision': '0123456789abcdef',
                 'subscription': {
                     'name': 'Config 1',
                     'contact_email': '*****@*****.**',
                     'bug_labels': ['Some-Label'],
                     'bug_components': ['Some>Component'],
                     'auto_triage': {
                         'enable': False
                     },
                     'auto_bisection': {
                         'enable': False
                     },
                     'rules': {},
                 }
             }, {
                 'config_set': 'projects/project',
                 'revision': '0123456789abcdef',
                 'subscription': {
                     'name': 'Config 2',
                     'contact_email': '*****@*****.**',
                     'bug_labels': ['Some-Label'],
                     'bug_components': ['Some>Component'],
                     'auto_triage': {
                         'enable': False
                     },
                     'auto_bisection': {
                         'enable': False
                     },
                     'rules': {},
                 }
             }, {
                 'config_set': 'projects/other_project',
                 'revision': '0123456789abcdff',
                 'subscription': {
                     'name': 'Expected 1',
                     'monorail_project_id': 'non-chromium',
                     'contact_email': '*****@*****.**',
                     'bug_labels': ['Some-Label'],
                     'bug_components': ['Some>Component'],
                     'auto_triage': {
                         'enable': False
                     },
                     'auto_bisection': {
                         'enable': False
                     },
                     'rules': {},
                 }
             }]
         })
     response = client.post('/subscriptions/list',
                            json={'identity_email': '*****@*****.**'},
                            headers={'X-Forwarded-Proto': 'https'})
     self.assertEqual(response.status_code, 200)
     self.assertDictEqual(response.get_json(), {})
Ejemplo n.º 9
0
 def testListSubscriptions(self):
     app = service.CreateApp({
         'environ': {
             'GOOGLE_CLOUD_PROJECT': 'chromeperf',
             'GAE_SERVICE': 'sheriff-config',
         },
         'datastore_client':
         datastore.Client(credentials=credentials.AnonymousCredentials(),
                          project='chromeperf'),
         'http':
         HttpMockSequenceWithDiscovery([({
             'status': '200'
         }, self.sample_config), ({
             'status': '200'
         }, '{ "is_member": true }'),
                                        ({
                                            'status': '200'
                                        }, '{ "is_member": false }')]),
     })
     client = app.test_client()
     response = client.get('/configs/update',
                           headers={'X-Forwarded-Proto': 'https'})
     self.assertEqual(response.status_code, 200)
     response = client.post('/subscriptions/list',
                            json={'identity_email': '*****@*****.**'},
                            headers={'X-Forwarded-Proto': 'https'})
     self.assertEqual(response.status_code, 200)
     self.assertDictEqual(
         response.get_json(), {
             'subscriptions': [{
                 'config_set': 'projects/project',
                 'revision': '0123456789abcdef',
                 'subscription': {
                     'name': 'Config 1',
                     'notification_email': '*****@*****.**',
                     'bug_labels': ['Some-Label'],
                     'bug_components': ['Some>Component'],
                     'patterns': [{
                         'glob': 'project/**'
                     }]
                 }
             }, {
                 'config_set': 'projects/project',
                 'revision': '0123456789abcdef',
                 'subscription': {
                     'name':
                     'Config 2',
                     'notification_email':
                     '*****@*****.**',
                     'bug_labels': ['Some-Label'],
                     'bug_components': ['Some>Component'],
                     'patterns': [{
                         'regex':
                         '^project/platform/.*/memory_peak$'
                     }]
                 }
             }, {
                 'config_set': 'projects/other_project',
                 'revision': '0123456789abcdff',
                 'subscription': {
                     'name': 'Expected 1',
                     'notification_email': '*****@*****.**',
                     'bug_labels': ['Some-Label'],
                     'bug_components': ['Some>Component'],
                     'patterns': [{
                         'glob': 'Master/Bot/Test/Metric/Something'
                     }]
                 }
             }]
         })
     response = client.post('/subscriptions/list',
                            json={'identity_email': '*****@*****.**'},
                            headers={'X-Forwarded-Proto': 'https'})
     self.assertEqual(response.status_code, 200)
     self.assertDictEqual(response.get_json(), {})
Ejemplo n.º 10
0
This test suite exercises the HTTP handlers from the Flask application defined
in the service module.
"""

# Support python3
from __future__ import absolute_import

import unittest
import json
import service

# Set up the app under test as a global.
APP = service.CreateApp({
    'environ': {
        'GAE_APPLICATION': 'chromeperf',
        'GAE_SERVICE': 'sheriff-config'
    }
})


class ServiceTest(unittest.TestCase):
    def setUp(self):
        self.client = APP.test_client()

    def tearDown(self):
        self.client = None


class ValidationTest(ServiceTest):
    def testServiceMetadata(self):
        # We want to ensure that we can get a valid service metadata description