Exemple #1
0
def test_admin_user_01(signed_in_op: OP, expected_data):
    # get item "Example Login 1" --vault "Test Data"
    server_name = "Example Server"
    vault = "Test Data"
    expected = _lookup_item_data(expected_data, server_name)
    result: OPServerItem = signed_in_op.get_item(server_name, vault=vault)
    assert result.username == expected["username"]
def test_get_item_02(signed_in_op: OP, expected_data):
    # get item nok7367v4vbsfgg2fczwu4ei44
    item_uuid = "nok7367v4vbsfgg2fczwu4ei44"
    expected = _lookup_item_data(expected_data, item_uuid)
    result = signed_in_op.get_item(item_uuid)
    assert result.username == expected["username"]
    assert result.password == expected["password"]
def test_get_item_03(signed_in_op: OP, expected_data):
    # get item "Example Login" --vault Archive
    item_name = "Example Login"
    vault = "Archive"
    expected = _lookup_item_data(expected_data, item_name)
    result: OPLoginItem = signed_in_op.get_item(item_name, vault=vault)
    assert result.username == expected["username"]
    assert result.password == expected["password"]
def test_get_item_01(signed_in_op: OP, expected_data):
    # get item "Example Login 1" --vault "Test Data"
    item_name = "Example Login 1"
    vault = "Test Data"
    expected = _lookup_item_data(expected_data, item_name)
    result = signed_in_op.get_item(item_name, vault=vault)
    assert result.username == expected["username"]
    assert result.password == expected["password"]
Exemple #5
0
def do_signin():
    # If you've already signed in at least once, you don't need to provide all
    # account details on future sign-ins. Just master password
    my_password = getpass.getpass(prompt="1Password master password:\n")
    # You may optionally provide an account shorthand if you used a custom one during initial sign-in
    # shorthand = "arbitrary_account_shorthand"
    # return OP(account_shorthand=shorthand, password=my_password)
    # Or we'll try to look up account shorthand from your latest sign-in in op's config file
    return OP(password=my_password)
def test_get_invalid_item_01(signed_in_op: OP, expected_data):
    item_name = "Invalid Item"
    expected = _lookup_item_data(expected_data, item_name)
    try:
        _ = signed_in_op.get_item(item_name)
        assert False, "We should have caught an exception"
    except OPGetItemException as e:
        print(e)
        assert e.returncode == expected["returncode"]
def test_get_document_01(signed_in_op: OP, expected_data):
    item_name = "Example Login 2 - 1200px-SpongeBob_SquarePants_character.svg.png.webp"
    vault = "Test Data"
    expected = _lookup_item_data(expected_data, item_name)
    filename, data = signed_in_op.get_document(item_name, vault=vault)
    sha256_digest = digest(data)
    assert filename == expected["filename"]
    assert len(data) == expected["size"]
    assert sha256_digest == expected["digest"]
Exemple #8
0
def do_initial_signin():
    my_signin_address = input("1Password sign-in address:\n")
    my_email_address = input("1Password email address:\n")
    my_secret_key = getpass.getpass(prompt="1Password secret key:\n")
    my_password = getpass.getpass(prompt="1Password master password:\n")

    return OP(signin_address=my_signin_address,
              email_address=my_email_address,
              secret_key=my_secret_key,
              password=my_password)
Exemple #9
0
def test_ssh_priv_key_01(signed_in_op: OP, expected_data):
    server_name = "Example Server"
    vault = "Test Data"
    keyname = "id_ed25519"
    expected_key_data = _lookup_ssh_key_data(expected_data, server_name,
                                             keyname)
    server_item: OPServerItem = signed_in_op.get_item(server_name, vault=vault)

    priv_key = server_item.field_value_by_section_title("SSH Keys", keyname)
    priv_key_digest = digest(priv_key.encode("utf-8"))
    assert priv_key_digest == expected_key_data["privkey_digest"]
Exemple #10
0
def test_ssh_key_passphrase_01(signed_in_op: OP, expected_data):
    server_name = "Example Server"
    vault = "Test Data"
    keyname = "id_ed25519"
    passphrase_field = f"{keyname} passphrase"
    expected_key_data = _lookup_ssh_key_data(expected_data, server_name,
                                             keyname)
    server_item: OPServerItem = signed_in_op.get_item(server_name, vault=vault)

    passphrase = server_item.field_value_by_section_title(
        "SSH Keys", passphrase_field)
    assert passphrase == expected_key_data["passphrase"]
def do_signin():
    # If you've already signed in at least once, you don't need to provide all
    # account details on future sign-ins. Just master password
    my_password = getpass.getpass(prompt="1Password master password:\n")
    return OP(password=my_password)
Exemple #12
0
if __name__ == "__main__":
    try:
        op = do_signin()
    except OPSigninException as opse:
        print("1Password sign-in failed.")
        print(opse.err_output)
        exit(opse.returncode)
    account_shorthand = op.account_shorthand
    print("Doing signout.")
    try:
        op.signout()
    except OPSignoutException as e:
        print("Signout failed.")
        print(e.err_output)
        exit(e.returncode)

    print("Forgetting account: {}.".format(account_shorthand))
    try:
        OP.forget(account_shorthand)
    except OPForgetException as e:
        print(e.err_output)
        exit(e.returncode)
    print("Done.")

    print("Trying to re-sign-in")
    try:
        do_signin()
    except OPSigninException as opse:
        print("1Password sign-in failed.")
        print(opse.err_output)
Exemple #13
0
def _get_signed_in_op(account_shorthand, default_vault=None):
    os.environ["MOCK_OP_RESPONSE_DIRECTORY"] = str(RESP_DIRECTORY_PATH)
    os.environ["MOCK_OP_SIGNIN_SUCCEED"] = "1"
    op = OP(vault=default_vault, account_shorthand=account_shorthand, password=OP_MASTER_PASSWORD, op_path='mock-op')
    return op
def do_signin(vault="Machine Credentials"):
    my_password = getpass.getpass(prompt="1Password master password:\n")
    return OP(vault=vault, password=my_password)
Exemple #15
0
def test_admin_password_01(signed_in_op: OP, expected_data):
    server_name = "Example Server"
    vault = "Test Data"
    expected = _lookup_item_data(expected_data, server_name)
    result: OPServerItem = signed_in_op.get_item(server_name, vault=vault)
    assert result.password == expected["password"]