Beispiel #1
0
def test_set_password_with_session(bw, db):
    bw.side_effect = ["mysession", '{"a": "b"}', None]

    session = bwkr.get_session({"BW_SESSION": "bla"})

    bwkr.set_password("c", "d", "e", session=session)

    payload = (b"eyJhIjogImIiLCAibmFtZSI6ICJjIiwgIm5vdGVzIjogbnVsbCw"
               b"gImxvZ2luIjogeyJ1cmlzIjogW3sibWF0Y2giOiBudWxsLCAidXJ"
               b"pIjogImMifV0sICJ1c2VybmFtZSI6ICJkIiwgInBhc3N3b3JkIjog"
               b"ImUifX0=")

    bw.assert_called_with("create", "item", payload)

    assert json.loads(base64.b64decode(payload).decode("utf-8")) == {
        "a": "b",
        "login": {
            "password": "******",
            "uris": [{
                "match": None,
                "uri": "c"
            }],
            "username": "******",
        },
        "name": "c",
        "notes": None,
    }
def test_get_session_login(bw, db):
    db.return_value = io.StringIO("{}")
    bw.return_value = "yo"

    assert bwkr.get_session({}) == "yo"

    bw.assert_called_with("login", "--raw")
def test_get_session(mocker):
    mocker.patch("bitwarden_keyring.user_is_authenticated", return_value=True)
    ask_for_session = mocker.patch("bitwarden_keyring.ask_for_session",
                                   return_value="yo")

    assert bwkr.get_session({}) == "yo"

    ask_for_session.assert_called_with(command="unlock")
def test_get_session_environ_wrong_session(bw, db):
    bw.side_effect = [ValueError, "yo"]

    assert bwkr.get_session({"BW_SESSION": "bla"}) == "yo"

    assert bw.call_count == 2

    bw.assert_any_call("sync")
    bw.assert_any_call("unlock", "--raw")
Beispiel #5
0
def test_get_password_with_session(bw, db):
    bw.side_effect = [
        "mysession",
        None,
        '[{"login": {"username": "******", "password": "******"}}]',
    ]
    session = bwkr.get_session({"BW_SESSION": "bla"})

    assert bwkr.get_password("c", "a", session=session) == "b"
Beispiel #6
0
def test_delete_password_with_session(bw, db, mocker):
    bw.side_effect = [
        "mysession",
        None,
        '{"id": "a", "login": {"username": "******"}}',
        None,
    ]
    mocker.patch("bitwarden_keyring.input", return_value="yes")

    session = bwkr.get_session({"BW_SESSION": "bla"})

    bwkr.delete_password("c", "d", session=session)

    bw.assert_called_with("delete", "item", "a", session=session)
def test_get_session_unlock(bw, db):
    bw.return_value = "yo"

    assert bwkr.get_session({}) == "yo"

    bw.assert_called_with("unlock", "--raw")
def test_get_session_environ(bw):
    assert bwkr.get_session({"BW_SESSION": "bla"}) == "bla"