def test_basic_auth(self): # missing password here self.assertRaises(ValueError, helpers.BasicAuth, None) self.assertRaises(ValueError, helpers.BasicAuth, 'nkim', None) auth = helpers.BasicAuth('nkim') self.assertEqual(auth.login, 'nkim') self.assertEqual(auth.password, '') auth = helpers.BasicAuth('nkim', 'pwd') self.assertEqual(auth.login, 'nkim') self.assertEqual(auth.password, 'pwd') self.assertEqual(auth.encode(), 'Basic bmtpbTpwd2Q=')
def function588(self): with function147(self.attribute2267, router=Class273) as var4462: var1378 = client.ClientSession(loop=self.attribute2267, auth=helpers.BasicAuth('login', 'pass')) var3192 = {'Authorization': 'Basic b3RoZXJfbG9naW46cGFzcw==', } with self.assertRaises(ValueError): self.attribute2267.run_until_complete(var1378.request('get', var4462.url('method', 'get'), headers=var3192)) var1378.close()
def test_session_auth_override(self): with run_server(self.loop, router=Functional) as httpd: session = client.ClientSession(loop=self.loop, auth=helpers.BasicAuth( "login", "pass")) r = self.loop.run_until_complete( session.request('get', httpd.url('method', 'get'), auth=helpers.BasicAuth("other_login", "pass"))) self.assertEqual(r.status, 200) content = self.loop.run_until_complete(r.json()) self.assertIn("Authorization", content['headers']) self.assertEqual(content['headers']["Authorization"], "Basic b3RoZXJfbG9naW46cGFzcw==") r.close() session.close()
def function248(self): with function147(self.attribute2267, router=Class273) as var1255: var4057 = client.ClientSession(loop=self.attribute2267, auth=helpers.BasicAuth('login', 'pass')) var2920 = self.attribute2267.run_until_complete(var4057.request('get', var1255.url('method', 'get'), auth=helpers.BasicAuth('other_login', 'pass'))) self.assertEqual(var2920.status, 200) var4442 = self.attribute2267.run_until_complete(var2920.json()) self.assertIn('Authorization', var4442['headers']) self.assertEqual(var4442['headers']['Authorization'], 'Basic b3RoZXJfbG9naW46cGFzcw==') var2920.close() var4057.close()
def function659(self): with function147(self.attribute2267, router=Class273) as var3816: var1840 = client.ClientSession(loop=self.attribute2267, auth=helpers.BasicAuth('login', 'pass')) var2341 = self.attribute2267.run_until_complete(var1840.request('get', var3816.url('method', 'get'))) self.assertEqual(var2341.status, 200) var4209 = self.attribute2267.run_until_complete(var2341.json()) self.assertIn('Authorization', var4209['headers']) self.assertEqual(var4209['headers']['Authorization'], 'Basic bG9naW46cGFzcw==') var2341.close() var1840.close()
def test_session_auth_header_conflict(self): with run_server(self.loop, router=Functional) as httpd: session = client.ClientSession( loop=self.loop, auth=helpers.BasicAuth("login", "pass")) headers = {'Authorization': "Basic b3RoZXJfbG9naW46cGFzcw=="} with self.assertRaises(ValueError): self.loop.run_until_complete( session.request('get', httpd.url('method', 'get'), headers=headers)) session.close()
def test_basic_auth1() -> None: # missing password here with pytest.raises(ValueError): helpers.BasicAuth(None)
@pytest.mark.parametrize('header', ('Basic ???', 'Basic ')) def test_basic_auth_decode_illegal_chars_base64(header) -> None: with pytest.raises(ValueError, match='Invalid base64 encoding.'): helpers.BasicAuth.decode(header) def test_basic_auth_decode_invalid_credentials() -> None: with pytest.raises(ValueError, match='Invalid credentials.'): header = 'Basic {}'.format(base64.b64encode(b'username').decode()) helpers.BasicAuth.decode(header) @pytest.mark.parametrize('credentials, expected_auth', ( (':', helpers.BasicAuth(login='', password='', encoding='latin1')), ('username:'******'username', password='', encoding='latin1')), (':password', helpers.BasicAuth(login='', password='******', encoding='latin1')), ('username:password', helpers.BasicAuth( login='******', password='******', encoding='latin1')), )) def test_basic_auth_decode_blank_username(credentials, expected_auth) -> None: header = 'Basic {}'.format(base64.b64encode(credentials.encode()).decode()) assert helpers.BasicAuth.decode(header) == expected_auth def test_basic_auth_from_url() -> None: url = URL('http://*****:*****@example.com')
def test_basic_auth3() -> None: auth = helpers.BasicAuth("nkim") assert auth.login == "nkim" assert auth.password == ""
def test_basic_auth3() -> None: auth = helpers.BasicAuth('nkim') assert auth.login == 'nkim' assert auth.password == ''
def function2440(): var3291 = helpers.BasicAuth('nkim', 'pwd') assert (var3291.login == 'nkim') assert (var3291.password == 'pwd') assert (var3291.encode() == 'Basic bmtpbTpwd2Q=')
def function1986(): var1830 = helpers.BasicAuth('nkim') assert (var1830.login == 'nkim') assert (var1830.password == '')
def function1819(): with pytest.raises(ValueError): helpers.BasicAuth('nkim:1', 'pwd')
def function520(): with pytest.raises(ValueError): helpers.BasicAuth('nkim', None)
def function2169(): with pytest.raises(ValueError): helpers.BasicAuth(None)
def test_basic_auth2() -> None: with pytest.raises(ValueError): helpers.BasicAuth('nkim', None)
def test_basic_with_auth_colon_in_login() -> None: with pytest.raises(ValueError): helpers.BasicAuth('nkim:1', 'pwd')
@pytest.mark.parametrize("header", ("Basic ???", "Basic ")) def test_basic_auth_decode_illegal_chars_base64(header) -> None: with pytest.raises(ValueError, match="Invalid base64 encoding."): helpers.BasicAuth.decode(header) def test_basic_auth_decode_invalid_credentials() -> None: with pytest.raises(ValueError, match="Invalid credentials."): header = "Basic {}".format(base64.b64encode(b"username").decode()) helpers.BasicAuth.decode(header) @pytest.mark.parametrize( "credentials, expected_auth", ( (":", helpers.BasicAuth(login="", password="", encoding="latin1")), ( "username:"******"username", password="", encoding="latin1"), ), ( ":password", helpers.BasicAuth(login="", password="******", encoding="latin1"), ), ( "username:password", helpers.BasicAuth( login="******", password="******", encoding="latin1"), ),
def test_basic_auth4() -> None: auth = helpers.BasicAuth('nkim', 'pwd') assert auth.login == 'nkim' assert auth.password == 'pwd' assert auth.encode() == 'Basic bmtpbTpwd2Q='
def test_basic_auth4() -> None: auth = helpers.BasicAuth("nkim", "pwd") assert auth.login == "nkim" assert auth.password == "pwd" assert auth.encode() == "Basic bmtpbTpwd2Q="