Skip to main content

Sharing Service Tests

Overview

Integration tests for the sharing-service, testing the complete lifecycle of device sharing, invitations, and permission management against a live service.

Running Tests

cd /backend
make test sharing

Test Configuration

  • Auth URL: http://localhost:80/api/auth (via gateway)
  • Device URL: http://localhost:80/api/devices (via gateway)
  • Sharing URL: http://localhost:80/api/sharing (via gateway)
  • Database: Direct PostgreSQL connection for test setup/cleanup
  • Email Domain: @test.vislagps.com (generated per test)

Test Flows

Test ClassDescription
TestHealthhealth check returns 200
TestShareAndAcceptFlowowner shares → target accepts → target sees device
TestSharePermissionsshare with specific perms → owner updates perms → target perms change
TestRevokeShareowner revokes → target loses access (403)
TestLeaveDevicetarget leaves → target loses access (403)
TestCannotShareWithSelfowner cannot share with self (400)
TestCannotShareTwiceduplicate share returns 409 Conflict
TestNonOwnerCannotShareshared user cannot share with others (403)
TestCancelInviteowner cancels invite → target cannot accept (404)
TestOwnerCannotLeaveowner cannot leave their own device (400)
TestShareNonExistentUsershare with non-existent email returns 404

Helper Functions

Located in tests/helpers.py:

Database Setup

FunctionDescription
create_user(role, email?, password?)Create user directly in DB
delete_user(user_id)Delete user and their device links
create_device_for_user(user_id, ...)Create device and link to user (owner)
delete_device(device_id)Delete device and all links/tokens

Authentication

FunctionDescription
login_user(auth_client, email, password)Login via auth API, returns access token
get_auth_headers(access_token)Create Authorization: Bearer header

Sharing API Calls

FunctionDescription
check_health(client)Verify service is healthy
share_device(client, headers, dev_id, email, ...)POST /devices/{id}/share
list_shares(client, headers, dev_id)GET /devices/{id}/shares
update_share(client, headers, dev_id, uid, perms)PUT /devices/{id}/shares/{uid}
revoke_share(client, headers, dev_id, uid)DELETE /devices/{id}/shares/{uid}
leave_device(client, headers, dev_id)DELETE /devices/{id}/leave
list_invites(client, headers)GET /invites
accept_invite(client, headers, token)POST /invites/accept
cancel_invite(client, headers, token)DELETE /invites/{token}

Test Strategy

Tests use a hybrid approach:

  1. Direct DB: helper functions create users and devices directly in PostgreSQL to ensure isolation and bypass the need for email verification or complex setup flows.
  2. Auth API: Real login via auth-service establishes a valid JWT session.
  3. Gateway API: All sharing operations go through the Nginx gateway to verify header propagation (X-User-Id, X-User-Role) and service integration.

Permissions Tested

OperationOwnerShared UserNon-Shared User
Share Device
Update Share
Revoke Share
Leave DeviceN/A
List Shares
View Device
Cancel InviteN/AN/A
Accept InviteN/AN/A