Add test case which verifies that st2 login works correctly and that
X-Auth-Token is indeed sent in the header in subsequent requests after
st2 login to st2 API.
@@ -145,6 +145,9 @@ class TestLoginIntPwdAndConfig(TestLoginBase):
@mock.patch.object(
requests, 'post',
mock.MagicMock(return_value=base.FakeResponse(json.dumps(TOKEN), 200, 'OK')))
+ @mock.patch.object(
+ requests, 'get',
+ mock.MagicMock(return_value=base.FakeResponse(json.dumps({}), 200, 'OK')))
@mock.patch('st2client.commands.auth.getpass')
def runTest(self, mock_gp):
'''Test 'st2 login' functionality with interactive password entry
@@ -157,18 +160,14 @@ class TestLoginIntPwdAndConfig(TestLoginBase):
self.shell.run(args)
- # TODO(mierdin): This tests that this particular command sends X-Auth-Token but you should
- # also test other commands after this token has been installed
- kwargs = {
+ expected_kwargs = {
'headers': {'content-type': 'application/json'},
'auth': ('st2admin', 'Password1!')
}
- requests.post.assert_called_with('http://127.0.0.1:9100/tokens', '{}', **kwargs)
+ requests.post.assert_called_with('http://127.0.0.1:9100/tokens', '{}', **expected_kwargs)
with open(self.CONFIG_FILE, 'r') as config_file:
-
for line in config_file.readlines():
-
# Make sure certain values are not present
self.assertFalse('password' in line)
self.assertFalse('olduser' in line)
@@ -180,6 +179,18 @@ class TestLoginIntPwdAndConfig(TestLoginBase):
# validate token was created
self.assertTrue(os.path.isfile('%stoken-%s' % (self.DOTST2_PATH, expected_username)))
+ # Validate token is sent on subsequent requests to st2 API
+ args = ['--config', self.CONFIG_FILE, 'pack', 'list']
+ self.shell.run(args)
+
+ expected_kwargs = {
+ 'headers': {
+ 'X-Auth-Token': self.TOKEN['token']
+ },
+ 'params': {}
+ }
+ requests.get.assert_called_with('http://127.0.0.1:9101/v1/packs', **expected_kwargs)
+
class TestLoginWritePwdOkay(TestLoginBase):
