def test_parse_args_save_path(self): self.assertEqual( parse_args(["--save", "/tmp/profiles.json"]).save_path, "/tmp/profiles.json") self.assertEqual(parse_args(["site"]).save_path, None) with patch.dict("os.environ", {"XDG_CONFIG_HOME": "/tmp"}): self.assertEqual( parse_args(["--save"]).save_path, "/tmp/lesspass/profiles.json")
def test_validate_args_no_opposite_rules_lowercase(self): error, message = validate_args( parse_args(["site", "-l", "--no-lowercase"])) self.assertTrue(error) self.assertTrue( "Can't have -l (--lowercase) and --no-lowercase at the same time" in message)
def test_validate_args_no_opposite_rules_symbols(self): error, message = validate_args( parse_args(["site", "-s", "--no-symbols"])) self.assertTrue(error) self.assertTrue( "Can't have -s (--symbols) and --no-symbols at the same time" in message)
def test_validate_args_no_opposite_rules_digits(self): error, message = validate_args( parse_args(["site", "-d", "--no-digits"])) self.assertTrue(error) self.assertTrue( "Can't have -d (--digits) and --no-digits at the same time" in message)
def main(args=sys.argv[1:]): args = parse_args(args) if args.version: print(__version__) sys.exit(0) error, help_message = validate_args(args) if args.help: print_help(help_message, long=True) sys.exit(0) if error: print_help(help_message) sys.exit(0) profile, master_password = create_profile(args) if not master_password: master_password = getpass.getpass("Master Password: "******"Copied to clipboard") except Exception as e: print("Copy failed, we are sorry") print("Can you send us an email at [email protected]\n") print("-" * 80) print("Object: [LessPass][cli] Copy issue on %s" % platform.system()) print("Hello,") print("I got an issue with LessPass cli software.\n") traceback.print_exc() print("-" * 80) else: print(generated_password)
def main(args=sys.argv[1:]): args = parse_args(args) if args.clipboard and not get_system_copy_command(): print( "error: To use the option -c (--copy) you need pbcopy on OSX, " + "xsel, xclip, or wl-clipboard on Linux, and clip on Windows" ) sys.exit(3) if args.save_path: return save_password_profiles(args.config_home_path, args.url, args.save_path) if args.load_path: return load_password_profiles(args.config_home_path, args.url, args.load_path) if args.prompt: if not args.site: args.site = getpass.getpass("Site: ") if not args.login: args.login = getpass.getpass("Login: "******"error: argument SITE is required but was not provided.") sys.exit(4) if not args.master_password: prompt = "Master Password: "******"error: argument MASTER_PASSWORD is required but was not provided") sys.exit(5) profile, master_password = create_profile(args) try: generated_password = generate_password(profile, master_password) except exceptions.ExcludeAllCharsAvailable: print("error: you can't exclude all chars available") sys.exit(6) if args.clipboard: try: copy(generated_password) print("Copied to clipboard") except Exception: print("Copy failed, we are sorry") print("Can you send us an email at [email protected]\n") print("-" * 80) print("Object: [LessPass][cli] Copy issue on %s" % platform.system()) print("Hello,") print("I got an issue with LessPass cli software.\n") traceback.print_exc() print("-" * 80) else: print(generated_password)
def test_validate_args_concat_errors(self): _, message = validate_args( parse_args(["site", "-u", "--no-uppercase", "-l", "--no-lowercase"]) ) self.assertTrue( "Can't have -l (--lowercase) and --no-lowercase at the same time" in message ) self.assertTrue( "Can't have -u (--uppercase) and --no-uppercase at the same time" in message )
def test_create_profile_default(self): profile, master_password = create_profile(parse_args(["site", "login"])) self.assertTrue(profile["lowercase"]) self.assertTrue(profile["uppercase"]) self.assertTrue(profile["digits"]) self.assertTrue(profile["symbols"]) self.assertEqual(profile["length"], 16) self.assertEqual(profile["counter"], 1) self.assertEqual(profile["site"], "site") self.assertEqual(profile["login"], "login") self.assertIsNone(master_password)
def main(args=sys.argv[1:]): args = parse_args(args) if args.clipboard and not get_system_copy_command(): print("ERROR To use the option -c (--copy) you need pbcopy " + "on OSX, xsel or xclip on Linux, and clip on Windows") sys.exit(3) if args.prompt: args.site = getpass.getpass("Site: ") args.login = getpass.getpass("Login: "******"ERROR argument SITE is required but was not provided.") sys.exit(4) if not args.master_password: args.master_password = getpass.getpass("Master Password: "******"ERROR argument MASTER_PASSWORD is required but was not provided") sys.exit(5) profile, master_password = create_profile(args) generated_password = generate_password(profile, master_password) if args.clipboard: try: copy(generated_password) print("Copied to clipboard") except Exception as e: print("Copy failed, we are sorry") print("Can you send us an email at [email protected]\n") print("-" * 80) print("Object: [LessPass][cli] Copy issue on %s" % platform.system()) print("Hello,") print("I got an issue with LessPass cli software.\n") traceback.print_exc() print("-" * 80) else: print(generated_password)
def test_parse_args_counter_short(self): self.assertEqual(parse_args(["site", "-C99"]).counter, 99) self.assertEqual(parse_args(["site", "-C", "100"]).counter, 100)
def test_parse_args_counter_long(self): self.assertEqual(parse_args(["site", "--counter", "2"]).counter, 2)
def test_parse_args_counter_default(self): self.assertEqual(parse_args(["site"]).counter, 1)
def test_parse_args_length_short(self): self.assertEqual(parse_args(["site", "-L6"]).length, 6) self.assertEqual(parse_args(["site", "-L", "12"]).length, 12)
def test_parse_args_site(self): self.assertEqual(parse_args(["site"]).site, "site")
def test_parse_args_u(self): self.assertTrue(parse_args(["site", "-u"]).u) self.assertTrue(parse_args(["site", "--uppercase"]).u)
def main(args=sys.argv[1:]): args = parse_args(args) if args.clipboard and not get_system_copy_command(): print( "ERROR To use the option -c (--copy) you need pbcopy " + "on OSX, xsel or xclip on Linux, and clip on Windows" ) sys.exit(3) if args.prompt_all: args.site = getpass.getpass("Site: ") args.login = getpass.getpass("Login: "******"Counter: ") if counter.isdigit(): args.counter = int(counter) else: print("ERROR argument COUNTER must be an integer.") sys.exit(4) length = getpass.getpass("Length [5-35]: ") try: length = int(length) if length >= 5 and length <= 35: args.length = length else: raise except: print("ERROR argument LENGTH must be an integer in range [5-35].") sys.exit(4) args.nl = True if getpass.getpass("Lowercase (Y/n): ") == 'n' else False args.nu = True if getpass.getpass("Uppercase (Y/n): ") == 'n' else False args.nd = True if getpass.getpass("Digits (Y/n): ") == 'n' else False args.ns = True if getpass.getpass("Symbols (Y/n): ") == 'n' else False elif args.prompt: args.site = getpass.getpass("Site: ") args.login = getpass.getpass("Login: "******"ERROR argument SITE is required but was not provided.") sys.exit(4) if not args.master_password: args.master_password = getpass.getpass("Master Password: "******"ERROR argument MASTER_PASSWORD is required but was not provided") sys.exit(5) profile, master_password = create_profile(args) generated_password = generate_password(profile, master_password) if args.clipboard: try: copy(generated_password) print("Copied to clipboard") except Exception as e: print("Copy failed, we are sorry") print("Can you send us an email at [email protected]\n") print("-" * 80) print("Object: [LessPass][cli] Copy issue on %s" % platform.system()) print("Hello,") print("I got an issue with LessPass cli software.\n") traceback.print_exc() print("-" * 80) else: print(generated_password)
def test_parse_args_no_symbols(self): self.assertTrue(parse_args(["site", "--no-symbols"]).ns)
def test_parse_args_no_lowercase(self): self.assertTrue(parse_args(["site", "--no-lowercase"]).nl)
def test_parse_args_master_password(self): self.assertEqual( parse_args(["site", "login", "masterpassword"]).master_password, "masterpassword", )
def test_parse_args_luds(self): args = parse_args(["site", "-luds"]) self.assertTrue(args.l) self.assertTrue(args.u) self.assertTrue(args.d) self.assertTrue(args.s)
def test_parse_args_s(self): self.assertTrue(parse_args(["site", "-s"]).s) self.assertTrue(parse_args(["site", "--symbols"]).s)
def test_parse_args_d(self): self.assertTrue(parse_args(["site", "-d"]).d) self.assertTrue(parse_args(["site", "--digits"]).d)
def test_parse_args_clipboard_default(self): self.assertFalse(parse_args(["site"]).clipboard)
def test_parse_args_length_default(self): self.assertEqual(parse_args(["site"]).length, 16)
def test_parse_args_clipboard_long(self): self.assertTrue(parse_args(["site", "--copy"]).clipboard)
def test_parse_args_length_long(self): self.assertEqual(parse_args(["site", "--length", "8"]).length, 8)
def test_parse_args_no_uppercase(self): self.assertTrue(parse_args(["site", "--no-uppercase"]).nu)
def test_parse_args_l(self): self.assertTrue(parse_args(["site", "-l"]).l) self.assertTrue(parse_args(["site", "--lowercase"]).l)
def test_validate_args_no_site(self): error, message = validate_args(parse_args([])) self.assertTrue(error) self.assertTrue( "SITE is a required argument" in message )
def test_parse_args_no_digits(self): self.assertTrue(parse_args(["site", "--no-digits"]).nd)