def test_load_agents_into_cookies(self): cookies = requests.cookies.RequestsCookieJar() c1, key = agent.load_agent_file( self.agent_filename, cookies=cookies, ) self.assertEqual(c1, cookies) self.assertEqual( key.encode(nacl.encoding.Base64Encoder), b'CqoSgj06Zcgb4/S6RT4DpTjLAfKoznEY3JsShSjKJEU=', ) self.assertEqual( key.public_key.encode(nacl.encoding.Base64Encoder), b'YAhRSsth3a36mRYqQGQaLiS4QJax0p356nd+B8x7UQE=', ) value = cookies.get('agent-login', domain='1.example.com') jv = base64.b64decode(value) if six.PY3: jv = jv.decode('utf-8') data = json.loads(jv) self.assertEqual(data['username'], 'user-1') self.assertEqual(data['public_key'], 'YAhRSsth3a36mRYqQGQaLiS4QJax0p356nd+B8x7UQE=') value = cookies.get('agent-login', domain='2.example.com', path='/discharger') jv = base64.b64decode(value) if six.PY3: jv = jv.decode('utf-8') data = json.loads(jv) self.assertEqual(data['username'], 'user-2') self.assertEqual(data['public_key'], 'YAhRSsth3a36mRYqQGQaLiS4QJax0p356nd+B8x7UQE=')
def test_load_agents_with_no_username(self): with self.assertRaises(agent.AgentFileFormatError): agent.load_agent_file(self.no_username_agent_filename)
def test_load_agents_with_bad_key(self): with self.assertRaises(agent.AgentFileFormatError): agent.load_agent_file(self.bad_key_agent_filename)