def test_dumps_and_loads_succeed(self): password = randomPassword() string = dumpsPassword(password) loaded_password = loadsPassword(string) self.assertEqual(password, loaded_password)
def dumpURL(config: Config) -> str: config = config._replace(password=dumpsPassword(config.password)) url_temp = 'http://{serverAddr}:{serverPort}/#{password}' url = url_temp.format_map(config._asdict()) return url
def test_dumps_and_loads_fail(self): password = randomPassword() password[random.randint(1, 255)] = 0 with self.assertRaises(InvalidPasswordError): dumpsPassword(password) string = base64.encodebytes(password).decode('utf8', errors='strict') with self.assertRaises(InvalidPasswordError): loadsPassword(string) password = randomPassword() password = password[:-2] with self.assertRaises(InvalidPasswordError): dumpsPassword(password) string = dumpsPassword(IDENTITY_PASSWORD) string = string[:-3] with self.assertRaises(InvalidPasswordError): loadsPassword(string)
def dump(f: typing.TextIO, config: Config) -> None: config = config._replace(password=dumpsPassword(config.password)) json.dump(config._asdict(), f, indent=2)
def dumps(config: Config) -> str: config = config._replace(password=dumpsPassword(config.password)) return json.dumps(config._asdict(), indent=2)