Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ celerybeat.pid
*.sage.py

# Environments
.env
.venv
env/
venv/
Expand Down Expand Up @@ -158,3 +157,6 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# Temp files
temp/
12 changes: 12 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"python.testing.unittestArgs": [
"-v",
"-s",
"./tests",
"-p",
"test_*.py"
],
"python.envFile": "${workspaceFolder}/tests/e2e/.env",
"python.testing.pytestEnabled": false,
"python.testing.unittestEnabled": true
}
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ client.set_user_enabled(user.Id, enabled=True)
from vaultwarden.clients.bitwarden import BitwardenAPIClient
from vaultwarden.models.bitwarden import Organization, OrganizationCollection, get_organization

bitwarden_client = BitwardenAPIClient(url="https://vaultwarden.example.com", email="admin@example", password="admin_password", client_id="client_id", client_secret="client_secret")
bitwarden_client = BitwardenAPIClient(url="https://vaultwarden.example.com", email="admin@example", password="admin_password", client_id="client_id", client_secret="client_secret", device_id="my_test_device")

org_uuid = "550e8400-e29b-41d4-a716-446655440000"

Expand Down Expand Up @@ -135,10 +135,15 @@ You can now install the project and its dependencies using:
pip install -e .[test]
```
### Testing
To run the tests, use:
Configure the test by loading the environment variables
```bash
set -a; . tests/e2e/.env; set +a
```
_this is proconfigrued for vscode python test extention_

To run the tests, use:
```bash
bash tests/e2e/run_tests.sh
python -m unittests discover
```

## License
Expand Down
11 changes: 11 additions & 0 deletions tests/e2e/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
VAULTWARDEN_VERSION="testing"
VAULTWARDEN_URL="http://localhost:8080"
VAULTWARDEN_ADMIN_TOKEN="admin"
VAULTWARDEN_INVITATIONS_ALLOWED="true"
BITWARDEN_URL="http://localhost:8080"
BITWARDEN_EMAIL="[email protected]"
BITWARDEN_PASSWORD="test-account"
BITWARDEN_CLIENT_ID="user.a8be340c-856b-481f-8183-2b7712995da2"
BITWARDEN_CLIENT_SECRET="ag66paVUq4h7tBLbCbJOY5tJkQvUuT"
BITWARDEN_TEST_ORGANIZATION="cda840d2-1de0-4f31-bd49-b30dacd7e8b0"
BITWARDEN_DEVICE_ID="e54ba5f5-7d58-4830-8f2b-99194c70c14f"
13 changes: 13 additions & 0 deletions tests/e2e/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
services:
vaultwarden:
image: vaultwarden/server:${VAULTWARDEN_VERSION}
container_name: python_vaultwarden_test
ports:
- "8080:80"
volumes:
- ./temp:/data
environment:
INVITATIONS_ALLOWED: ${VAULTWARDEN_INVITATIONS_ALLOWED}
I_REALLY_WANT_VOLATILE_STORAGE: "true"
ADMIN_TOKEN: ${VAULTWARDEN_ADMIN_TOKEN}
restart: unless-stopped
15 changes: 15 additions & 0 deletions tests/e2e/docker_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import os
import shutil
from time import sleep

def start_docker():
shutil.copytree("tests/fixtures/server", "tests/e2e/temp/", dirs_exist_ok=True)
os.system("docker compose -f tests/e2e/compose.yaml up -d")
sleep(1)

def stop_docker():
os.system("docker compose -f tests/e2e/compose.yaml down")
try:
shutil.rmtree("tests/e2e/temp")
except FileNotFoundError:
pass
45 changes: 0 additions & 45 deletions tests/e2e/run_tests.sh

This file was deleted.

17 changes: 13 additions & 4 deletions tests/e2e/test_bitwarden.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,30 @@
from vaultwarden.clients.bitwarden import BitwardenAPIClient
from vaultwarden.models.bitwarden import get_organization

from .docker_helper import start_docker, stop_docker

# Get Bitwarden credentials from environment variables
url = os.environ.get("BITWARDEN_URL", None)
email = os.environ.get("BITWARDEN_EMAIL", None)
password = os.environ.get("BITWARDEN_PASSWORD", None)
client_id = os.environ.get("BITWARDEN_CLIENT_ID", None)
client_secret = os.environ.get("BITWARDEN_CLIENT_SECRET", None)
device_id = os.environ.get("BITWARDEN_DEVICE_ID", None)
bitwarden = BitwardenAPIClient(
url, email, password, client_id, client_secret, device_id
)

# Get test organization id from environment variables
test_organization = os.environ.get("BITWARDEN_TEST_ORGANIZATION", None)


class BitwardenBasic(unittest.TestCase):
def tearDownClass() -> None:
stop_docker()

def setUp(self) -> None:
self.organization = get_organization(bitwarden, test_organization)
start_docker()
self.bitwarden = BitwardenAPIClient(
url, email, password, client_id, client_secret, device_id
)
self.organization = get_organization(self.bitwarden, test_organization)
self.test_colls_names = self.organization.collections(as_dict=True)
self.test_colls_ids = self.organization.collections()
self.test_users = self.organization.users()
Expand All @@ -39,6 +45,9 @@ def setUp(self) -> None:
"test-collection-2"
).users()

def tearDown(self) -> None:
stop_docker()

def test_get_organization_users(self):
self.assertEqual(len(self.test_users), 2)

Expand Down
9 changes: 9 additions & 0 deletions tests/e2e/test_vaultwarden.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@

from vaultwarden.clients.vaultwarden import VaultwardenAdminClient

from .docker_helper import start_docker, stop_docker

# Get Vaultwarden Admin credentials from environment variables
url = os.environ.get("VAULTWARDEN_URL", None)
admin_token = os.environ.get("VAULTWARDEN_ADMIN_TOKEN", None)


# TODO Add tests for VaultwardenAdminClient
class VaultwardenAdminClientBasic(unittest.TestCase):
def tearDownClass() -> None:
stop_docker()

def setUp(self) -> None:
start_docker()
self.vaultwarden = VaultwardenAdminClient(
url=url, admin_secret_token=admin_token
)

def tearDown(self) -> None:
stop_docker()