def test_user_agent(self, _afd, _obt, det, _client): # Normally the client is totally mocked out, but here we need more # arguments to automate it... args = [ "--standalone", "certonly", "-m", "*****@*****.**", "-d", "example.com", '--agree-tos' ] + self.standard_args det.return_value = mock.MagicMock(), None with mock.patch('letsencrypt.cli.client.acme_client.ClientNetwork' ) as acme_net: self._call_no_clientmock(args) os_ver = " ".join(le_util.get_os_info()) ua = acme_net.call_args[1]["user_agent"] self.assertTrue(os_ver in ua) import platform plat = platform.platform() if "linux" in plat.lower(): self.assertTrue(platform.linux_distribution()[0] in ua) with mock.patch('letsencrypt.cli.client.acme_client.ClientNetwork' ) as acme_net: ua = "bandersnatch" args += ["--user-agent", ua] self._call_no_clientmock(args) acme_net.assert_called_once_with(mock.ANY, verify_ssl=True, user_agent=ua)
def test_user_agent(self, _afd, _obt, det, _client): # Normally the client is totally mocked out, but here we need more # arguments to automate it... args = [ "--standalone", "certonly", "-m", "*****@*****.**", "-d", "example.com", "--agree-tos", ] + self.standard_args det.return_value = mock.MagicMock(), None with mock.patch("letsencrypt.cli.client.acme_client.ClientNetwork") as acme_net: self._call_no_clientmock(args) os_ver = " ".join(le_util.get_os_info()) ua = acme_net.call_args[1]["user_agent"] self.assertTrue(os_ver in ua) import platform plat = platform.platform() if "linux" in plat.lower(): self.assertTrue(platform.linux_distribution()[0] in ua) with mock.patch("letsencrypt.cli.client.acme_client.ClientNetwork") as acme_net: ua = "bandersnatch" args += ["--user-agent", ua] self._call_no_clientmock(args) acme_net.assert_called_once_with(mock.ANY, verify_ssl=True, user_agent=ua)
def os_constant(key): """Get a constant value for operating system :param key: name of cli constant :return: value of constant for active os """ os_info = le_util.get_os_info() try: constants = CLI_DEFAULTS[os_info[0].lower()] except KeyError: constants = CLI_DEFAULTS["debian"] return constants[key]
def _determine_user_agent(config): """ Set a user_agent string in the config based on the choice of plugins. (this wasn't knowable at construction time) :returns: the client's User-Agent string :rtype: `str` """ if config.user_agent is None: ua = "LetsEncryptPythonClient/{0} ({1}) Authenticator/{2} Installer/{3}" ua = ua.format(letsencrypt.__version__, " ".join(le_util.get_os_info()), config.authenticator, config.installer) else: ua = config.user_agent return ua