def test_http_error(self):
        tokenRequest = util.setup_expected_client_cred_token_request_response(403)

        with six.assertRaisesRegex(self, Exception, '403'):
            context = adal.AuthenticationContext(cp['authUrl'])
            token_response = context.acquire_token_with_client_credentials(
                 cp['resource'], cp['clientId'], cp['clientSecret'])
    def test_http_error(self):
        tokenRequest = util.setup_expected_client_cred_token_request_response(403)

        with self.assertRaisesRegexp(Exception, "403"):
            adal.acquire_token_with_client_credentials(
                cp["authUrl"], cp["clientId"], cp["clientSecret"], cp["resource"]
            )
    def test_http_error(self):
        tokenRequest = util.setup_expected_client_cred_token_request_response(
            403)

        with six.assertRaisesRegex(self, Exception, '403'):
            context = adal.AuthenticationContext(cp['authUrl'])
            token_response = context.acquire_token_with_client_credentials(
                cp['resource'], cp['clientId'], cp['clientSecret'])
Esempio n. 4
0
    def test_http_error(self):
        tokenRequest = util.setup_expected_client_cred_token_request_response(
            403)

        with self.assertRaisesRegexp(Exception, '403'):
            adal.acquire_token_with_client_credentials(cp['authUrl'],
                                                       cp['clientId'],
                                                       cp['clientSecret'],
                                                       cp['resource'])
    def test_success_with_junk_return(self):
        junkResponse = 'This is not properly formated return value.'

        tokenRequest = util.setup_expected_client_cred_token_request_response(200, junkResponse)

        with self.assertRaises(Exception):
            context = adal.AuthenticationContext(cp['authUrl'])
            token_response = context.acquire_token_with_client_credentials(
                 cp['resource'], cp['clientId'], cp['clientSecret'])
    def test_success_with_junk_return(self):
        junkResponse = "This is not properly formated return value."

        tokenRequest = util.setup_expected_client_cred_token_request_response(200, junkResponse)

        with self.assertRaises(Exception):
            adal.acquire_token_with_client_credentials(
                cp["authUrl"], cp["clientId"], cp["clientSecret"], cp["resource"]
            )
    def test_error_with_junk_return(self):
        junkResponse = 'This is not properly formated return value.'

        tokenRequest = util.setup_expected_client_cred_token_request_response(
            400, junkResponse)

        with self.assertRaises(Exception):
            context = adal.AuthenticationContext(cp['authUrl'])
            token_response = context.acquire_token_with_client_credentials(
                cp['resource'], cp['clientId'], cp['clientSecret'])
Esempio n. 8
0
    def test_success_dynamic_instance_discovery(self):
        instanceDiscoveryRequest = util.setup_expected_instance_discovery_request(
            200,
            cp['authorityHosts']['global'],
            {'tenant_discovery_endpoint' : 'http://foobar'},
            self.nonHardCodedAuthorizeEndpoint
        )

        responseOptions = { 'authority' : self.nonHardCodedAuthority}
        response = util.create_response(responseOptions)
        wireResponse = response['wireResponse']

        util.setup_expected_client_cred_token_request_response(200, wireResponse, self.nonHardCodedAuthority)

        token_response = adal.acquire_token_with_client_credentials(
            self.nonHardCodedAuthority, cp['clientId'], cp['clientSecret'], response['resource'])
        self.assertTrue(
            util.is_match_token_response(response['cachedResponse'], token_response),
            'The response does not match what was expected.: ' + str(token_response)
        )
Esempio n. 9
0
    def test_success_with_junk_return(self):
        junkResponse = 'This is not properly formated return value.'

        tokenRequest = util.setup_expected_client_cred_token_request_response(
            200, junkResponse)

        with self.assertRaises(Exception):
            adal.acquire_token_with_client_credentials(cp['authUrl'],
                                                       cp['clientId'],
                                                       cp['clientSecret'],
                                                       cp['resource'])
    def test_happy_path(self):
        response_options = {"noRefresh": True}
        response = util.create_response(response_options)
        token_request = util.setup_expected_client_cred_token_request_response(200, response["wireResponse"])

        token_response = adal.acquire_token_with_client_credentials(
            cp["authUrl"], cp["clientId"], cp["clientSecret"], response["resource"]
        )
        self.assertTrue(
            util.is_match_token_response(response["cachedResponse"], token_response),
            "The response does not match what was expected.: " + str(token_response),
        )
    def test_happy_path(self):
        response_options = { 'noRefresh' : True, 'tokenEndpoint': True }
        response = util.create_response(response_options)
        token_request = util.setup_expected_client_cred_token_request_response(200, response['wireResponse'])

        context = adal.AuthenticationContext(cp['authUrl'])
        token_response = context.acquire_token_with_client_credentials(
             response['resource'], cp['clientId'], cp['clientSecret'])
        self.assertTrue(
            util.is_match_token_response(response['cachedResponse'], token_response),
            'The response does not match what was expected.: ' + str(token_response)
        )
    def test_oauth_error(self):
        errorResponse = {
          'error' : 'invalid_client',
          'error_description' : 'This is a test error description',
          'error_uri' : 'http://errordescription.com/invalid_client.html'
        }

        tokenRequest = util.setup_expected_client_cred_token_request_response(400, errorResponse)

        with six.assertRaisesRegex(self, Exception, 'Get Token request returned http error: 400 and server response:'):
            context = adal.AuthenticationContext(cp['authUrl'])
            token_response = context.acquire_token_with_client_credentials(
                 cp['resource'], cp['clientId'], cp['clientSecret'])
    def test_success_dynamic_instance_discovery(self):
        instanceDiscoveryRequest = util.setup_expected_instance_discovery_request(
            200,
            cp["authorityHosts"]["global"],
            {"tenant_discovery_endpoint": "http://foobar"},
            self.nonHardCodedAuthorizeEndpoint,
        )

        responseOptions = {"authority": self.nonHardCodedAuthority}
        response = util.create_response(responseOptions)
        wireResponse = response["wireResponse"]

        util.setup_expected_client_cred_token_request_response(200, wireResponse, self.nonHardCodedAuthority)

        context = adal.AuthenticationContext(self.nonHardCodedAuthority)
        token_response = context.acquire_token_with_client_credentials(
            response["resource"], cp["clientId"], cp["clientSecret"]
        )
        self.assertTrue(
            util.is_match_token_response(response["cachedResponse"], token_response),
            "The response does not match what was expected.: " + str(token_response),
        )
    def test_oauth_error(self):
        errorResponse = {
            "error": "invalid_client",
            "error_description": "This is a test error description",
            "error_uri": "http://errordescription.com/invalid_client.html",
        }

        tokenRequest = util.setup_expected_client_cred_token_request_response(400, errorResponse)

        with self.assertRaisesRegexp(Exception, "Get Token request returned http error: 400 and server response:"):
            adal.acquire_token_with_client_credentials(
                cp["authUrl"], cp["clientId"], cp["clientSecret"], cp["resource"]
            )
    def test_happy_path(self):
        response_options = {'noRefresh': True, 'tokenEndpoint': True}
        response = util.create_response(response_options)
        token_request = util.setup_expected_client_cred_token_request_response(
            200, response['wireResponse'])

        context = adal.AuthenticationContext(cp['authUrl'])
        token_response = context.acquire_token_with_client_credentials(
            response['resource'], cp['clientId'], cp['clientSecret'])
        self.assertTrue(
            util.is_match_token_response(response['cachedResponse'],
                                         token_response),
            'The response does not match what was expected.: ' +
            str(token_response))
    def performStaticInstanceDiscovery(self, authorityHost):
        hardCodedAuthority = "https://" + authorityHost + "/" + cp["tenant"]

        responseOptions = {"authority": hardCodedAuthority}
        response = util.create_response(responseOptions)
        wireResponse = response["wireResponse"]
        tokenRequest = util.setup_expected_client_cred_token_request_response(200, wireResponse, hardCodedAuthority)

        context = adal.AuthenticationContext(hardCodedAuthority)
        token_response = context.acquire_token_with_client_credentials(
            response["resource"], cp["clientId"], cp["clientSecret"]
        )

        self.assertTrue(
            util.is_match_token_response(response["cachedResponse"], token_response),
            "The response does not match what was expected.: " + str(token_response),
        )
    def test_oauth_error(self):
        errorResponse = {
            'error': 'invalid_client',
            'error_description': 'This is a test error description',
            'error_uri': 'http://errordescription.com/invalid_client.html'
        }

        tokenRequest = util.setup_expected_client_cred_token_request_response(
            400, errorResponse)

        with six.assertRaisesRegex(
                self, Exception,
                'Get Token request returned http error: 400 and server response:'
        ):
            context = adal.AuthenticationContext(cp['authUrl'])
            token_response = context.acquire_token_with_client_credentials(
                cp['resource'], cp['clientId'], cp['clientSecret'])
Esempio n. 18
0
    def performStaticInstanceDiscovery(self, authorityHost, callback):
        hardCodedAuthority = 'https://' + authorityHost + '/' + cp['tenant']

        responseOptions = {
            'authority' : hardCodedAuthority
        }
        response = util.create_response(responseOptions)
        wireResponse = response['wireResponse']
        tokenRequest = util.setup_expected_client_cred_token_request_response(200, wireResponse, hardCodedAuthority)

        token_response = adal.acquire_token_with_client_credentials(
            hardCodedAuthority, cp['clientId'], cp['clientSecret'], response['resource'])

        self.assertTrue(
            util.is_match_token_response(response['cachedResponse'], token_response),
            'The response does not match what was expected.: ' + str(token_response)
        )