Exemple #1
0
 def test_authenticated_failed_get(self):
     """ The authenticated failed get should throw a BadCredentials exception """
     TEST_URI = "http://testme.com/test.html"
     CONTENT = "hello world"
     httpretty.register_uri(httpretty.GET, TEST_URI,
                            body=CONTENT, status=401)
     lib.authenticated_get("username", "password", TEST_URI)
Exemple #2
0
 def test_authenticated_failed_get(self):
     """ The authenticated failed get should throw a BadCredentials exception """
     TEST_URI = "http://testme.com/test.html"
     CONTENT = "hello world"
     httpretty.register_uri(httpretty.GET, TEST_URI,
                            body=CONTENT, status=401)
     lib.authenticated_get("username", "password", TEST_URI)
Exemple #3
0
 def __load_manifest(self, raw_manifest, username=None, password=None, verify_certificate=True):
     manifest = configparser.RawConfigParser()
     manifest.add_section('config')
     if isinstance(raw_manifest, string_types):
         if raw_manifest.startswith("http"):
             # raw_manifest is a url
             if username and password:
                 manifest_file_handler = StringIO(lib.authenticated_get(username,
                                                                        password,
                                                                        raw_manifest,
                                                                        verify=verify_certificate).decode("utf-8"))
             else:
                 manifest_file_handler = StringIO(requests.get(raw_manifest).text)
             manifest.readfp(manifest_file_handler)
         else:
             # raw_manifest is a filepath
             if not os.path.exists(os.path.expanduser(raw_manifest)):
                 raise ManifestException("Manifest does not exist at %s!" % raw_manifest)
             manifest.read(raw_manifest)
         if not manifest.has_option('config', 'source'):
             manifest.set('config', 'source', str(raw_manifest))
     elif raw_manifest.__class__ == configparser.RawConfigParser:
         return raw_manifest
     else:
         manifest.readfp(raw_manifest)
     return manifest
Exemple #4
0
 def test_authenticated_get(self):
     """ The authenticated get should pass in authentication headers """
     TEST_URI = "http://testme.com/test.html"
     CONTENT = "hello world"
     httpretty.register_uri(httpretty.GET, TEST_URI,
                            body=CONTENT)
     returned_content = lib.authenticated_get("username", "password", TEST_URI)
     tools.eq_(returned_content.decode("utf-8"), CONTENT)
     tools.ok_("Authorization" in httpretty.last_request().headers)
     tools.eq_(httpretty.last_request().headers["Authorization"],
               "Basic %s" % b64encode(('%s:%s' % ("username", "password")).encode("latin1")).strip().decode("utf-8"))
Exemple #5
0
 def test_authenticated_get(self):
     """ The authenticated get should pass in authentication headers """
     TEST_URI = "http://testme.com/test.html"
     CONTENT = "hello world"
     httpretty.register_uri(httpretty.GET, TEST_URI,
                            body=CONTENT)
     returned_content = lib.authenticated_get("username", "password", TEST_URI)
     tools.eq_(returned_content.decode("utf-8"), CONTENT)
     tools.ok_("Authorization" in httpretty.last_request().headers)
     tools.eq_(httpretty.last_request().headers["Authorization"],
               "Basic %s" % b64encode(('%s:%s' % ("username", "password")).encode("latin1")).strip().decode("utf-8"))
Exemple #6
0
def _load_manifest_from_url(manifest, url, verify_certificate=True, username=None, password=None):
    """ load a url body into a manifest """
    try:
        if username and password:
            manifest_file_handler = StringIO(lib.authenticated_get(username, password, url,
                                                                   verify=verify_certificate).decode("utf-8"))
        else:
            manifest_file_handler = StringIO(lib.cleaned_request('get', url).text)
        manifest.readfp(manifest_file_handler)
    except requests.exceptions.RequestException:
        logger.debug("", exc_info=True)
        error_message = sys.exc_info()[1]
        raise ManifestException("There was an error retrieving {0}!\n {1}".format(url, str(error_message)))
Exemple #7
0
def _load_manifest_from_url(manifest,
                            url,
                            verify_certificate=True,
                            username=None,
                            password=None):
    """ load a url body into a manifest """
    try:
        if username and password:
            manifest_file_handler = StringIO(
                lib.authenticated_get(
                    username, password, url,
                    verify=verify_certificate).decode("utf-8"))
        else:
            manifest_file_handler = StringIO(
                lib.cleaned_request('get', url).text)
        manifest.readfp(manifest_file_handler)
    except requests.exceptions.RequestException:
        logger.debug("", exc_info=True)
        error_message = sys.exc_info()[1]
        raise ManifestException(
            "There was an error retrieving {0}!\n {1}".format(
                url, str(error_message)))
Exemple #8
0
 def __load_manifest(self, raw_manifest, username=None, password=None, verify_certificate=True):
     manifest = configparser.RawConfigParser()
     manifest.add_section('config')
     try:
         if isinstance(raw_manifest, string_types):
             if raw_manifest.startswith("http"):
                 # raw_manifest is a url
                 try:
                     if username and password:
                         manifest_file_handler = StringIO(lib.authenticated_get(username,
                                                                                password,
                                                                                raw_manifest,
                                                                                verify=verify_certificate).decode("utf-8"))
                     else:
                         manifest_file_handler = StringIO(lib.cleaned_request('get', raw_manifest).text)
                     manifest.readfp(manifest_file_handler)
                 except requests.exceptions.RequestException:
                     self.logger.debug("", exc_info=True)
                     error_message = sys.exc_info()[1]
                     raise ManifestException("There was an error retrieving {0}!\n {1}".format(raw_manifest, str(error_message)))
             else:
                 # raw_manifest is a filepath
                 if not os.path.exists(os.path.expanduser(raw_manifest)):
                     raise ManifestException("Manifest does not exist at %s!" % raw_manifest)
                 manifest.read(raw_manifest)
             if not manifest.has_option('config', 'source'):
                 manifest.set('config', 'source', str(raw_manifest))
         elif raw_manifest.__class__ == configparser.RawConfigParser:
             return raw_manifest
         else:
             manifest.readfp(raw_manifest)
     except configparser.Error:
         self.logger.debug("", exc_info=True)
         error_message = sys.exc_info()[1]
         raise ManifestException("Unable to parse manifest!: {0}".format(error_message))
     return manifest