def setUp(self):
     generate_credentials_file()
     self.creds_provider = PropertiesCredentialsProvider(
     ).set_properties_file(fake_credentials_file)
     self.base = 'http://localhost:' + str(8080)
     generate_properties_file(self.base, fake_credentials_file)
     self.token_provider = None
 def testRealCloudGetAuthorizationStringAndToken(self):
     generate_properties_file(idcs_url(), credentials_file)
     self.token_provider = DefaultAccessTokenProvider(
         idcs_props_file=properties_file)
     # get authorization string for ListTablesRequest
     result = self.token_provider.get_authorization_string(
         ListTablesRequest())
     self.assertIsNotNone(result)
     # get authorization string for TableRequest
     result = self.token_provider.get_authorization_string(
         TableRequest())
     self.assertIsNotNone(result)
     # get account access token
     result = self.token_provider.get_account_access_token()
     self.assertIsNotNone(result)
     # get service access token
     result = self.token_provider.get_service_access_token()
     self.assertIsNotNone(result)
    def testAccessTokenProviderGetAccountAccessToken(self):
        account_at = 'account-at'

        class TokenHandler(SimpleHTTPRequestHandler):
            def do_GET(self):
                rawpath = self.path.split('?')[0]
                if rawpath == APP_ENDPOINT:
                    self.send_response(codes.ok)
                    self.send_header('Content-Type', 'application/json')
                    self.send_header('Content-Length', str(len(CLIENT_INFO)))
                    self.end_headers()
                    self.wfile.write(CLIENT_INFO.encode())

            def do_POST(self):
                rawpath = self.path.split('?')[0]
                if rawpath == TOKEN_ENDPOINT:
                    res = str.format(TOKEN_RESULT, account_at)
                    self.send_response(codes.ok)
                    self.send_header('Content-Type', 'application/json')
                    self.send_header('Content-Length', str(len(res)))
                    self.end_headers()
                    self.wfile.write(res.encode())

        httpd, port = self.__find_port_start_server(TokenHandler)

        # connect to illegal idcs url
        self.base = 'http://localhost:80'
        generate_properties_file(self.base, fake_credentials_file)
        self.token_provider = DefaultAccessTokenProvider(properties_file)
        self.assertRaises(ConnectionError,
                          self.token_provider.get_account_access_token)
        self.token_provider.close()

        self.base = 'http://localhost:' + str(port)
        # connect to legal idcs url
        generate_properties_file(self.base, fake_credentials_file)
        self.token_provider = DefaultAccessTokenProvider(properties_file)
        result = self.token_provider.get_account_access_token()
        self.assertIsNotNone(result)
        self.assertEqual(result, account_at)
        self.__stop_server(httpd)
Ejemplo n.º 4
0
    def testAccessTokenProviderGetAccountAccessToken(self):
        global GET_INFO, POST_INFO
        GET_INFO = CLIENT_INFO
        POST_INFO = None
        httpd, port = self._find_port_start_server(TokenHandler)

        # connect to illegal idcs url
        self.base = 'http://localhost:80'
        generate_properties_file(self.base, fake_credentials_file)
        self.token_provider = DefaultAccessTokenProvider(properties_file)
        self.assertRaises(ConnectionError,
                          self.token_provider.get_account_access_token)
        self.token_provider.close()

        self.base = 'http://localhost:' + str(port)
        # connect to legal idcs url
        generate_properties_file(self.base, fake_credentials_file)
        self.token_provider = DefaultAccessTokenProvider(properties_file)
        result = self.token_provider.get_account_access_token()
        self.assertIsNotNone(result)
        self.assertEqual(result, ACCOUNT_AT)
        self._stop_server(httpd)