The Simplest Way to Make Pytest and Webauthn Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

You pair pytest and webauthn by running automated tests with virtual passkeys instead of hardware keys. This setup lets your team check passwordless sign-in flows on every build without manual clicks. Real hardware keys need a human finger to touch a physical button during sign-in. Automated test suites cannot press physical buttons inside a build pipeline. By using virtual keys in your browser runner, your tests can create and sign challenges on their own. How pytest and webauthn pass keys a

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You pair pytest and webauthn by running automated tests with virtual passkeys instead of hardware keys. This setup lets your team check passwordless sign-in flows on every build without manual clicks.

Real hardware keys need a human finger to touch a physical button during sign-in. Automated test suites cannot press physical buttons inside a build pipeline. By using virtual keys in your browser runner, your tests can create and sign challenges on their own.

How pytest and webauthn pass keys and permissions

To test passkeys, your test runner must talk to both your app and a virtual key store. First, the test starts a browser session and sets up a virtual key device. Next, the test asks your app to start a new key sign-up or sign-in flow.

Your app sends a random challenge back to the browser session. The virtual key device signs this challenge with its private key right away. It sends the signed payload back to your app to finish the check.

During this flow, your test checks that the app stores the public key in the database. It also checks that the user gets a valid session with the right permissions. Each test run should create a fresh virtual key and wipe it when the test ends.

Common failure modes and how to scope test roles

Teams often break their passkey tests by taking risky shortcuts in the build pipeline. One common mistake is turning off passkey checks in test builds and using a shared password instead. This leaves your real sign-in code untested until it hits production.

Another failure mode is sharing one static test account with broad admin tokens across many test runs. When tests run at the same time, they overwrite key counters and cause random test failures. Worse, broad test tokens can leak into logs and give too much power to a single script.

FIDO2 / WebAuthn + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

You can fix this by giving each test worker its own scoped test user and minimal role. Set your app to check that the origin domain in the signed response matches your test server. Always log every key sign-up and sign-in event during the test run so you can audit failures.

Keeping test data and production systems separate

Automated tests often need database access to set up users or check saved public keys. Never let your test runner touch production databases or use live user records. Keep test network paths isolated so test scripts only talk to local or staging databases.

If your tests inspect user profiles, make sure any sensitive fields stay safe in your test outputs. Data masking can rewrite matched fields like emails, phone numbers, card numbers, or national IDs in results. This keeps test logs clean while your team checks that passkey flows work as expected.

Add runtime guardrails and masking beside your databases and APIs

Login rules, role grants, and CI checks govern who connects to your stack. Yet any allowed script, engineer, or AI agent still runs commands with the full scope of its role. For workloads on Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes, SSH, or internal HTTP services, hoop.dev sits beside the service as an open-source proxy, a sidecar for your database or API.

Before a query runs, hoop.dev guardrails check the statement against your rules. An AI Analyzer you configure can score intent or hold risky calls for human review. Next, hoop.dev data masking rewrites sensitive fields in responses, and each verdict is logged per listener. Explore the MIT-licensed project on GitHub.

Frequently asked questions

Can pytest run passkey tests without a physical security key?

Yes, your browser driver can create a software-based virtual key device in memory for each test. It signs challenges just like a hardware key without needing a human touch.

Why do my passkey tests fail when running in parallel?

Parallel tests fail when multiple workers share the same user account and increment the same signature counter. Give every test function its own isolated user record and fresh virtual key.

Should we bypass passkey checks in our staging pipeline?

No, bypassing passkey checks hides bugs in origin matching, challenge timeouts, and key counter updates. Always test the full sign-in flow with virtual keys before shipping code.

The query runs. The emails stay hidden.