def runTest(self, mock_gp):
        """Test 'st2 login' functionality with interactive password entry"""

        expected_username = self.TOKEN["user"]
        args = ["--config", self.CONFIG_FILE, "login", expected_username]

        mock_gp.getpass.return_value = "Password1!"

        self.shell.run(args)

        expected_kwargs = {
            "headers": {"content-type": "application/json"},
            "auth": ("st2admin", "Password1!"),
        }
        requests.post.assert_called_with(
            "http://127.0.0.1:9100/tokens", "{}", **expected_kwargs
        )

        # Check file permissions
        self.assertEqual(os.stat(self.CONFIG_FILE).st_mode & 0o777, 0o660)

        with open(self.CONFIG_FILE, "r") as config_file:
            for line in config_file.readlines():
                # Make sure certain values are not present
                self.assertNotIn("password", line)
                self.assertNotIn("olduser", line)

                # Make sure configured username is what we expect
                if "username" in line:
                    self.assertEqual(line.split(" ")[2][:-1], expected_username)

            # 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": {"include_attributes": "ref,name,description,version,author"},
        }
        requests.get.assert_called_with(
            "http://127.0.0.1:9101/v1/packs", **expected_kwargs
        )
Test 'st2 login' functionality with interactive password entry
st2client/tests/unit/test_auth.py