Exemple #1
0
 def testInvalidRegexAutoBisect(self):
     with self.assertRaisesRegex(validator.InvalidPattern, 'no argument'):
         _ = validator.Validate("""
                            subscriptions: [
                              {
                                name: "Empty Regex",
                                contact_email: "bad-pattern@domain",
                                bug_labels: ["test-blocker"],
                                bug_components: ["Sample>Component"],
                                rules: {
                                   match: [{regex: ".*"}]
                                }
                                auto_triage {
                                  rules: {
                                    match: {regex: ".*"}
                                  }
                                }
                                auto_bisection {
                                  rules: {
                                    match: {regex: "*"}
                                  }
                                }
                              }
                            ]
                          """)
     with self.assertRaisesRegex(validator.InvalidPattern, 'no argument'):
         _ = validator.Validate("""
                            subscriptions: [
                              {
                                name: "Empty Regex",
                                contact_email: "bad-pattern@domain",
                                bug_labels: ["test-blocker"],
                                bug_components: ["Sample>Component"],
                                rules: {
                                   match: [{regex: ".*"}]
                                   exclude: [{regex: ".*"}]
                                }
                                auto_triage {
                                  rules: {
                                    match: {regex: ".*"}
                                  }
                                }
                                auto_bisection {
                                  rules: {
                                    match: {regex: ".*"}
                                    exclude: {regex: "*"}
                                  }
                                }
                              }
                            ]
                          """)
Exemple #2
0
 def testGoodCase(self):
     subscriptions = validator.Validate("""
       subscriptions: [{
         name: "Release Team"
         contact_email: "*****@*****.**"
         bug_labels: ["release-blocker"]
         bug_components: ["Sample>Component"]
           rules: { match: [{glob: "project/**"}] }
       },
       {
         name: "Memory Team",
         contact_email: "*****@*****.**",
         bug_labels: ["memory-regressions"],
         rules: { match: [{regex: "^project/.*memory_.*$"}] },
         anomaly_configs: [
           {
             min_relative_change: 0.01
             rules: {
               match: {
                 regex: "^project/platform/.*/memory_peak$"
               }
             }
           }
         ]
       }]""")
     self.assertIsNotNone(subscriptions)
Exemple #3
0
 def testValidAutoTriageAndAutoBisect(self):
     _ = validator.Validate("""
                            subscriptions: [
                              {
                                name: "Empty Regex",
                                contact_email: "bad-pattern@domain",
                                bug_labels: ["test-blocker"],
                                bug_components: ["Sample>Component"],
                                rules: {
                                   match: [{regex: ".*"}]
                                   exclude: [{regex: ".*"}]
                                }
                                auto_triage {
                                  rules: {
                                    match: {regex: ".*"}
                                    exclude: {regex: ".*"}
                                  }
                                }
                                auto_bisection {
                                  rules: {
                                    match: {regex: ".*"}
                                    exclude: {regex: ".*"}
                                  }
                                }
                              }
                            ]
                          """)
Exemple #4
0
  def Transform(config):
    missing_fields = required_fields.difference(config)
    if len(missing_fields):
      raise InvalidConfigError(config, missing_fields)

    # We use a combination of the config set, revision, and content_hash to
    # identify this particular configuration.
    key = client.key(
        'Subscription',
        '{config_set}:{revision}'.format(**config),
        parent=subscription_index_key)
    try:
      sheriff_config = validator.Validate(
          base64.standard_b64decode(config['content']))
    except validator.Error as error:
      raise InvalidContentError(config, error)

    entity = datastore.Entity(
        key=key, exclude_from_indexes=['sheriff_config', 'url'])
    entity.update({
        'config_set': config['config_set'],
        'revision': config['revision'],
        'content_hash': config['content_hash'],
        'url': config['url'],
        'sheriff_config': sheriff_config.SerializeToString()
    })
    return (key, entity)
Exemple #5
0
 def testInvalidJSON(self):
     with self.assertRaisesRegexp(validator.InvalidJSON,
                                  'JSON Validation Error'):
         _ = validator.Validate("""
                          {
                          "subscriptions": ...
                          }
                          """)
Exemple #6
0
 def testMissingName(self):
   with self.assertRaises(validator.MissingName):
     _ = validator.Validate("""
                              subscriptions: [
                                {
                                  notification_email: "missing-name@domain",
                                  bug_labels: ["test-blocker"],
                                  bug_components: ["Sample>Component"],
                                  patterns: [{glob: "project/**"}]
                                }
                              ]
                            """)
Exemple #7
0
 def testMissingName(self):
     with self.assertRaises(validator.MissingName):
         _ = validator.Validate("""
                            subscriptions: [
                              {
                                contact_email: "missing-name@domain",
                                bug_labels: ["test-blocker"],
                                bug_components: ["Sample>Component"],
                                rules: { match: [{glob: "project/**"}] }
                              }
                            ]
                          """)
Exemple #8
0
 def testMissingPattern(self):
     with self.assertRaises(validator.MissingPatterns):
         _ = validator.Validate("""
                            subscriptions: [
                              {
                                name: "No Patterns",
                                contact_email: "no-patterns@domain",
                                bug_labels: ["test-blocker"],
                                bug_components: ["Sample>Component"]
                              }
                            ]
                          """)
Exemple #9
0
 def testMissingEmail(self):
     with self.assertRaises(validator.MissingEmail):
         _ = validator.Validate("""
                            subscriptions: [
                              {
                                name: "Missing Email",
                                bug_labels: ["test-blocker"],
                                bug_components: ["Sample>Component"],
                                rules: { match: [{glob: "project/**"}] }
                              }
                            ]
                          """)
Exemple #10
0
 def testInvalidRegexMatch(self):
     with self.assertRaisesRegex(validator.InvalidPattern, 'no argument'):
         _ = validator.Validate("""
                            subscriptions: [
                              {
                                name: "Empty Regex",
                                contact_email: "bad-pattern@domain",
                                bug_labels: ["test-blocker"],
                                bug_components: ["Sample>Component"],
                                rules: { match: [{regex: "*"}] }
                              }
                            ]
                          """)
Exemple #11
0
 def testMissingEmptyPattern(self):
   with self.assertRaises(validator.MissingPatterns):
     _ = validator.Validate("""
                              subscriptions: [
                                {
                                  name: "Empty List Patterns",
                                  notification_email: "no-patterns@domain",
                                  bug_labels: ["test-blocker"],
                                  bug_components: ["Sample>Component"],
                                  patterns: []
                                }
                              ]
                            """)
def UnionAsBinaryStringWithIndexedOffsetData(o, schema, path):
    representation = cStringIO.StringIO()
    for idx, possibleSchemaType in enumerate(schema['optionTypes']):
        if len(validator.Validate(possibleSchemaType, o)) == 0:
            binaryIndex = uint32.pack(idx)
            representation.write(binaryIndex)
            itemRepresentation, indexedOffsetData = RepresentAsBinaryWithIndexedOffsetData(o, possibleSchemaType, FsdDataPathObject('<%s>' % possibleSchemaType['type'], parent=path))
            if not indexedOffsetData.isEmpty():
                indexedOffsetData.AddOffset(len(binaryIndex))
            representation.write(itemRepresentation)
            return (representation.getvalue(), indexedOffsetData)

    raise ValueError('Could not represent %s as any type in union' % str(o))
Exemple #13
0
 def testInvalidEmptyGlob(self):
     with self.assertRaisesRegex(validator.InvalidPattern,
                                 'glob must not be empty'):
         _ = validator.Validate("""
                            subscriptions: [
                              {
                                name: "Empty Glob",
                                contact_email: "bad-pattern@domain",
                                bug_labels: ["test-blocker"],
                                bug_components: ["Sample>Component"],
                                rules: { match: [{glob: ""}] }
                              }
                            ]
                          """)
Exemple #14
0
 def testInvalidUndefinedPattern(self):
   with self.assertRaisesRegexp(validator.InvalidPattern,
                                'must provide either \'glob\' or \'regex\''):
     _ = validator.Validate("""
                              subscriptions: [
                                {
                                  name: "Bad Pattern",
                                  notification_email: "bad-pattern@domain",
                                  bug_labels: ["test-blocker"],
                                  bug_components: ["Sample>Component"],
                                  patterns: [{}]
                                }
                              ]
                            """)
Exemple #15
0
 def testInvalidEmptyRegex(self):
   with self.assertRaisesRegexp(validator.InvalidPattern,
                                'regex must not be empty'):
     _ = validator.Validate("""
                              subscriptions: [
                                {
                                  name: "Empty Regex",
                                  notification_email: "bad-pattern@domain",
                                  bug_labels: ["test-blocker"],
                                  bug_components: ["Sample>Component"],
                                  patterns: [{regex: ""}]
                                }
                              ]
                            """)
Exemple #16
0
 def testMissingPattern(self):
     with self.assertRaises(validator.MissingPatterns):
         _ = validator.Validate("""
                          {
                            "subscriptions": [
                              {
                                "name": "No Patterns",
                                "notification_email": "no-patterns@domain",
                                "bug_labels": ["test-blocker"],
                                "bug_components": ["Sample>Component"]
                              }
                            ]
                          }
                          """)
Exemple #17
0
 def testMissingName(self):
     with self.assertRaises(validator.MissingName):
         _ = validator.Validate("""
                          {
                            "subscriptions": [
                              {
                                "notification_email": "missing-name@domain",
                                "bug_labels": ["test-blocker"],
                                "bug_components": ["Sample>Component"],
                                "patterns": [{"glob": "project/**"}]
                              }
                            ]
                          }
                          """)
Exemple #18
0
 def testMissingEmail(self):
     with self.assertRaises(validator.MissingEmail):
         _ = validator.Validate("""
                          {
                            "subscriptions": [
                              {
                                "name": "Missing Email",
                                "bug_labels": ["test-blocker"],
                                "bug_components": ["Sample>Component"],
                                "patterns": [{"glob": "project/**"}]
                              }
                            ]
                          }
                          """)
Exemple #19
0
 def testInvalidEmptyRegex(self):
     with self.assertRaisesRegexp(validator.InvalidPattern,
                                  'regex must not be empty'):
         _ = validator.Validate("""
                          {
                            "subscriptions": [
                              {
                                "name": "Empty Regex",
                                "notification_email": "bad-pattern@domain",
                                "bug_labels": ["test-blocker"],
                                "bug_components": ["Sample>Component"],
                                "patterns": [{"regex": ""}]
                              }
                            ]
                          }
                          """)
Exemple #20
0
 def testValidAnomalyConfigs(self):
     _ = validator.Validate("""
   subscriptions: [
     {
       name: "Subscription"
       contact_email: "user@domain"
       bug_labels: ["test-blocker"],
       bug_components: ["Sample>Component"],
       rules: {
         match: [{regex: ".*"}]
       }
       anomaly_configs {
         rules {
           match: [{regex: ".*"}]
         }
       }
     }
   ]""")
Exemple #21
0
 def Validate():  # pylint: disable=unused-variable
     validation_request = request.get_json()
     if validation_request is None:
         return u'Invalid request.', 400
     for member in ('config_set', 'path', 'content'):
         if member not in validation_request:
             return u'Missing \'%s\' member in request.' % (member), 400
     try:
         _ = validator.Validate(validation_request['content'])
     except validator.Error as error:
         return jsonify({
             'messages': [{
                 'path': validation_request['path'],
                 'severity': 'ERROR',
                 'text': '%s' % (error)
             }]
         })
     return jsonify({})
Exemple #22
0
 def testGoodCase(self):
     subscriptions = validator.Validate("""{
       "subscriptions": [{
         "name": "Release Team",
         "notification_email": "*****@*****.**",
         "bug_labels": ["release-blocker"],
         "bug_components": ["Sample>Component"],
         "patterns": [{"glob": "project/**"}]
       },
       {
         "name": "Memory Team",
         "notification_email": "*****@*****.**",
         "bug_labels": ["memory-regressions"],
         "patterns": [{"regex": "^project/.*memory_.*$"}],
         "anomaly_configs": [
           {
             "min_relative_change": 0.01,
             "patterns": [{"regex": "^project/platform/.*/memory_peak$"}]
           }
         ]
       }]}""")
     self.assertIsNotNone(subscriptions)
Exemple #23
0
 def testMonorailProjectId(self):
     subscriptions = validator.Validate("""
       subscriptions: [{
         name: "Non-Chromium Team"
         contact_email: "*****@*****.**"
         bug_labels: ["release-blocker"]
         bug_components: ["Sample>Component"]
         monorail_project_id: "not-chromium"
         patterns: [{glob: "project/**"}]
       },
       {
         name: "Memory Team",
         contact_email: "*****@*****.**",
         bug_labels: ["memory-regressions"],
         patterns: [{regex: "^project/.*memory_.*$"}],
         anomaly_configs: [
           {
             min_relative_change: 0.01
             patterns: [{regex: "^project/platform/.*/memory_peak$"}]
           }
         ]
       }]""")
     self.assertIsNotNone(subscriptions)
Exemple #24
0
 def __init__(self, cfg_file='./midpoint.cfg', logFile=None):
     self.logger = Logger()
     self.connection = {}
     self.validate = validator.Validate(self.logger)
     self.read_config(cfg_file)
Exemple #25
0
 def testInvalidJSON(self):
     with self.assertRaisesRegex(validator.InvalidConfig,
                                 'SheriffConfig Validation Error'):
         _ = validator.Validate("""
                          subscriptions: ...
                          """)