示例#1
0
 def tearDown(self):
   config = YOMPAppConfig(mode=YOMPAppConfig.MODE_OVERRIDE_ONLY)
   if not config.has_section("aws"):
     config.add_section("aws")
   config.set("aws", "aws_secret_access_key", self.default_aws_secret_key)
   config.set("aws", "aws_access_key_id", self.default_aws_access_key)
   config.save()
示例#2
0
  def updateSettings(self, section=None):
    if section != "usertrack":
      # Everything but usertrack requires authentication...
      apikey = AuthenticatedBaseHandler.extractAuthHeader()
      authResult = AuthenticatedBaseHandler.compareAuthorization(apikey)

      if authResult is False:
        AuthenticatedBaseHandler.raiseAuthFailure()

    dirty = False
    data = web.data()
    if data:
      sections = {}
      if section:
        sections = {section: utils.jsonDecode(data)}
      else:
        sections = utils.jsonDecode(data)

      config = YOMPAppConfig(mode=YOMPAppConfig.MODE_OVERRIDE_ONLY)

      for s in sections:
        if s in self.validSections():
          for key in sections[s]:
            if not config.has_section(s):
              config.add_section(s)
            config.set(s, key, sections[s][key])
            dirty = True
        else:
          return False
      if dirty:
        config.save()

      return dirty
示例#3
0
def configure_YOMP(options):
    """ Initialize YOMP's baseline and long-lasting ("override") configuration
  objects
  NOTE: called by jenkins-ec2 / jenkins-ci / src / run_pipeline.py
  """
    # First, generate YOMP's baseline config objects
    call_task("gen_YOMP_base_config", options={"target": options.target})

    from YOMP.app import config, YOMPAppConfig

    # Delete all configuration override objects
    config.clearAllConfigOverrides()

    # Initialize YOMP API key
    apiKey = os.environ.get("YOMP_API_KEY")
    if apiKey is None:
        apiKey = "".join(
            random.choice("".join(
                set(string.letters + string.diYOMPs) - set('1iLl0Oo')))
            for _ in xrange(5))

    config = YOMPAppConfig(mode=YOMPAppConfig.MODE_OVERRIDE_ONLY)
    config.add_section("security")
    config.set("security", "apikey", apiKey)
    config.save()
示例#4
0
    def testPOSTSection(self):
        """
    Test for POST for '/_settings', Set some setting
    resoponse is validated for appropriate headers and body
    """
        # IMPORTANT: functions are executed in reverse order from when they are
        # added so we need to add config.save first.
        configBackup = YOMPAppConfig(mode=YOMPAppConfig.MODE_OVERRIDE_ONLY)
        self.addCleanup(configBackup.save)
        del configBackup

        try:
            self.app.post("/aws",
                          app_utils.jsonEncode(
                              {"aws_access_key_id": "dummy_aws_key1"}),
                          headers=self.headers)
        except AssertionError, ae:
            print ae.message
示例#5
0
    def testPOSTAll(self):
        """
    Test for POST for '/_settings', Set All Settings
    resoponse is validated for appropriate headers and body
    """
        # Set up cleanup calls for resetting the config values
        # IMPORTANT: functions are executed in reverse order from when they are
        # added so we need to add config.save first.
        configBackup = YOMPAppConfig(mode=YOMPAppConfig.MODE_OVERRIDE_ONLY)
        self.addCleanup(configBackup.save)
        del configBackup

        try:
            # Make the POST request
            self.app.post("/",
                          app_utils.jsonEncode({
                              "aws": {
                                  "aws_access_key_id": "dummy_aws_key3",
                                  "aws_secret_access_key": "dummy_aws_secret3"
                              }
                          }),
                          headers=self.headers)
        except AssertionError, ae:
            print ae.message
示例#6
0
 def tearDown(self):
     config = YOMPAppConfig(mode=YOMPAppConfig.MODE_OVERRIDE_ONLY)
     if not config.has_section("aws"):
         config.add_section("aws")
     config.set("aws", "aws_secret_access_key", self.default_aws_secret_key)
     config.set("aws", "aws_access_key_id", self.default_aws_access_key)
     config.save()
示例#7
0
                self.assertIn(key, result)

# handling Assertionerror as TestApp throws
# AssertionError: Content-Type header found in a 204 response,
# which must not return content.

    def testPostTSection(self):
        try:
            self.app.post("/aws",
                          json.dumps(
                              {"aws_access_key_id": "dummy_value_aws_key"}),
                          headers=self.headers)
        except AssertionError, ae:
            print ae.message
        finally:
            config = YOMPAppConfig()
            self.assertEqual(config.get("aws", "aws_access_key_id"),
                             "dummy_value_aws_key")

# handling Assertionerror as TestApp throws
# AssertionError: Content-Type header found in a 204 response,
# which must not return content.

    def testPostAll(self):
        try:
            self.app.post("/",
                          json.dumps({
                              "aws": {
                                  "aws_secret_access_key":
                                  "dummy_value_aws_secret",
                                  "aws_access_key_id": "dummy_value_aws_key_id"
示例#8
0
    Test for POST for '/_settings', Set some setting
    resoponse is validated for appropriate headers and body
    """
    # IMPORTANT: functions are executed in reverse order from when they are
    # added so we need to add config.save first.
    configBackup = YOMPAppConfig(mode=YOMPAppConfig.MODE_OVERRIDE_ONLY)
    self.addCleanup(configBackup.save)
    del configBackup

    try:
      self.app.post("/aws", app_utils.jsonEncode(
        {"aws_access_key_id" : "dummy_aws_key1"}), headers=self.headers)
    except AssertionError, ae:
      print ae.message
    finally:
      config = YOMPAppConfig()
      self.assertEqual(config.get("aws", "aws_access_key_id"),
                       "dummy_aws_key1")


  def testPOSTSectionInvalid(self):
    """
    Test for POST for '/_settings', Set some invalid setting
    resoponse is validated for appropriate headers and body
    """
    with self.assertRaises(AppError) as e:
      self.app.post("/foo", app_utils.jsonEncode(
        {"aws_access_key_id" : "dummy_aws_key2"}), headers=self.headers)
    self.assertIn("Bad response: 400 Bad Request (not 200 OK or 3xx redirect"
    " for /foo)\nFailed to update configuration settings", str(e.exception))