Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_create_from_url_no_header(self):
httpretty.register_uri(httpretty.GET, uri=self.testUrl, body='foo', status=401)
def _callback(err, resp):
self.assertIsNotNone(err, "Did not receive expected error.")
self.assertTrue(str(err).find('header') >= 0, 'Error did not include message about missing header')
adal.authentication_parameters.create_authentication_parameters_from_url(self.testUrl, _callback)
req = httpretty.last_request()
util.match_standard_request_headers(req)
httpretty.register_uri(httpretty.GET, uri=self.testUrl, body='foo', status=401, **{'www-authenticate':'Bearer authorization_uri="foobar,lkfj,;l,", fruitcake="f",resource="clark, &^()- q32,shark" , f="foo"'})
url_obj = urlparse(self.testUrl)
def _callback(err, parameters):
self.assertIsNone(err, "An error was raised during function {0}".format(err))
test_params = {
'authorizationUri' : 'foobar,lkfj,;l,',
'resource' : 'clark, &^()- q32,shark',
}
self.assertEqual(parameters.authorization_uri, test_params['authorizationUri'],
'Parsed authorizationUri did not match expected value.: {0}'.format(parameters.authorization_uri))
self.assertEqual(parameters.resource, test_params['resource'],
'Parsed resource did not match expected value.: {0}'.format(parameters.resource))
adal.authentication_parameters.create_authentication_parameters_from_url(url_obj, _callback)
req = httpretty.last_request()
util.match_standard_request_headers(req)
def test_create_from_url_network_error(self):
try:
adal.authentication_parameters.create_authentication_parameters_from_url('https://0.0.0.0/foobar')
except Exception as err:
self.assertIsNotNone(err, "Did not receive expected error.")
@httpretty.activate
def test_create_from_url_happy_string_url(self):
httpretty.register_uri(httpretty.GET, uri=self.testUrl, body='foo', status=401, **{'www-authenticate':'Bearer authorization_uri="foobar,lkfj,;l,", fruitcake="f",resource="clark, &^()- q32,shark" , f="foo"'})
# maybe try-catch here to catch the error
parameters = adal.authentication_parameters.create_authentication_parameters_from_url(self.testUrl)
test_params = {
'authorizationUri' : 'foobar,lkfj,;l,',
'resource' : 'clark, &^()- q32,shark',
}
self.assertEqual(parameters.authorization_uri, test_params['authorizationUri'],
'Parsed authorizationUri did not match expected value.: {0}'.format(parameters.authorization_uri))
self.assertEqual(parameters.resource, test_params['resource'],
'Parsed resource did not match expected value.: {0}'.format(parameters.resource))
req = httpretty.last_request()
util.match_standard_request_headers(req)
@httpretty.activate
def test_create_from_url_happy_path_url_object(self):
httpretty.register_uri(httpretty.GET, uri=self.testUrl, body='foo', status=401, **{'www-authenticate':'Bearer authorization_uri="foobar,lkfj,;l,", fruitcake="f",resource="clark, &^()- q32,shark" , f="foo"'})
url_obj = urlparse(self.testUrl)
try:
parameters = adal.authentication_parameters.create_authentication_parameters_from_url(url_obj)
test_params = {
'authorizationUri' : 'foobar,lkfj,;l,',
'resource' : 'clark, &^()- q32,shark',
}
self.assertEqual(parameters.authorization_uri, test_params['authorizationUri'],
'Parsed authorizationUri did not match expected value.: {0}'.format(parameters.authorization_uri))
self.assertEqual(parameters.resource, test_params['resource'],
'Parsed resource did not match expected value.: {0}'.format(parameters.resource))
except Exception as err:
self.assertIsNone(err, "An error was raised during function {0}".format(err))
req = httpretty.last_request()
util.match_standard_request_headers(req)
def test_create_from_url_happy_string_url(self):
httpretty.register_uri(httpretty.GET, uri=self.testUrl, body='foo', status=401, **{'www-authenticate':'Bearer authorization_uri="foobar,lkfj,;l,", fruitcake="f",resource="clark, &^()- q32,shark" , f="foo"'})
def _callback(err, parameters):
self.assertIsNone(err, "An error was raised during function {0}".format(err))
test_params = {
'authorizationUri' : 'foobar,lkfj,;l,',
'resource' : 'clark, &^()- q32,shark',
}
self.assertEqual(parameters.authorization_uri, test_params['authorizationUri'],
'Parsed authorizationUri did not match expected value.: {0}'.format(parameters.authorization_uri))
self.assertEqual(parameters.resource, test_params['resource'],
'Parsed resource did not match expected value.: {0}'.format(parameters.resource))
adal.authentication_parameters.create_authentication_parameters_from_url(self.testUrl, _callback, None)
req = httpretty.last_request()
util.match_standard_request_headers(req)
@httpretty.activate
def test_create_from_url_no_header(self):
httpretty.register_uri(httpretty.GET, uri=self.testUrl, body='foo', status=401)
receivedException = False
try:
adal.authentication_parameters.create_authentication_parameters_from_url(self.testUrl)
except Exception as err:
receivedException = True
self.assertTrue(str(err).find('header') >= 0, 'Error did not include message about missing header')
pass
finally:
self.assertTrue(receivedException)
req = httpretty.last_request()
util.match_standard_request_headers(req)
def test_create_from_url_bad_object(self):
def _callback(err, resp):
self.assertIsNotNone(err, "Did not receive expected error.")
adal.authentication_parameters.create_authentication_parameters_from_url({}, _callback)
def test_create_from_url_not_passed(self):
try:
parameters = adal.authentication_parameters.create_authentication_parameters_from_url(None)
except Exception as exp:
self.assertIsNotNone(exp, "Did not receive expected error.")
pass