JWT Library for Robot Framework
Project description
JWT Robot Framework Library
A comprehensive Robot Framework library for JSON Web Token (JWT) operations, enabling robust testing of JWT-based authentication and authorization in your test automation.
🚀 Features
- Complete JWT Lifecycle: Generate, decode, validate, and analyze JWT tokens
- Multiple Algorithms: Support for HMAC, RSA, ECDSA, and PSS algorithms
- Advanced Validation: Comprehensive claim validation, expiration checking, and signature verification
- Security-First: Built-in protection against common JWT vulnerabilities
- Easy Integration: Simple keyword interface designed for Robot Framework
- Extensive Documentation: Complete keyword reference with examples
- Error Handling: Graceful error handling with detailed error messages
- Performance Optimized: Efficient token operations for test automation
📦 Installation
Using pip
pip install robotframework-jwtlibrary
From source
git clone https://github.com/ohmrefresh/robotframework-jwtlibrary.git
cd jwt-robotframework-library
pip install -e .
Dependencies
- Python 3.7+
- Robot Framework 4.0+
- PyJWT 2.0+
🏃 Quick Start
Basic Usage
*** Settings ***
Library JWTLibrary
*** Variables ***
${SECRET_KEY} your-secret-key-here
*** Test Cases ***
Basic JWT Operations
# Create payload
${payload}= Create Dictionary user_id=123 role=admin
# Generate token
${token}= Generate JWT Token ${payload} ${SECRET_KEY}
# Decode and verify
${decoded}= Decode JWT Payload ${token} ${SECRET_KEY}
Should Be Equal ${decoded['user_id']} 123
# Validate token
${is_valid}= Verify JWT Token ${token} ${SECRET_KEY}
Should Be True ${is_valid}
Advanced Example
Advanced JWT Validation
# Create comprehensive payload
${payload}= Create Dictionary
... iss=auth-service
... sub=user-12345
... aud=api-service
... user_id=12345
... role=admin
... permissions=["read", "write", "delete"]
# Generate token with custom expiration
${token}= Generate JWT Token ${payload} ${SECRET_KEY} expiration_hours=2
# Comprehensive validation
${exp_info}= Check JWT Expiration ${token}
Should Be Equal ${exp_info['is_expired']} ${False}
${claims_valid}= Validate JWT Claims ${token}
... {"role": "admin", "user_id": 12345} ${SECRET_KEY} ${True}
Should Be True ${claims_valid}
${aud_valid}= Validate JWT Audience ${token} api-service
Should Be True ${aud_valid}
📚 Available Keywords
Token Generation
Generate JWT Token- Creates JWT tokens with custom payloadsGenerate JWT Token With Claims- Creates tokens using keyword argumentsGenerate JWT Token Without Expiration- Creates non-expiring tokensGenerate JWT Token With Custom Expiration- Creates tokens with specific expiration
Token Decoding
Decode JWT Payload- Decodes token payloads with optional verificationDecode JWT Header- Decodes token headersGet JWT Claim- Extracts specific claims from tokensGet Multiple JWT Claims- Extracts multiple claimsExtract All JWT Claims- Gets all claims with metadata
Token Validation
Verify JWT Token- Validates token signatures and expirationCheck JWT Expiration- Checks token expiration statusValidate JWT Claims- Validates expected claim valuesCheck JWT Algorithm- Validates token algorithmValidate JWT Structure- Validates token formatCheck JWT Not Before- Validates nbf claimValidate JWT Audience- Validates audience claim
Utilities
Create JWT Payload- Helper to create payload dictionariesGet JWT Token Info- Gets comprehensive token informationCompare JWT Tokens- Compares two tokensExtract JWT Timestamps- Extracts timestamp claimsGenerate Current Timestamp- Creates current timestampGenerate Future Timestamp- Creates future timestampConvert Timestamp To Datetime- Converts timestamps to datetime
🔧 Supported Algorithms
| Family | Algorithms | Description |
|---|---|---|
| HMAC | HS256, HS384, HS512 | Symmetric signing |
| RSA | RS256, RS384, RS512 | Asymmetric signing |
| ECDSA | ES256, ES384, ES512 | Elliptic curve signing |
| PSS | PS256, PS384, PS512 | RSA-PSS signing |
🎯 Use Cases
API Testing
Test API Authentication
${token}= Generate JWT Token {"user_id": 123} ${API_SECRET}
# Use token in API requests
${headers}= Create Dictionary Authorization=Bearer ${token}
${response}= GET ${API_URL}/protected headers=${headers}
Should Be Equal As Integers ${response.status_code} 200
Microservices Testing
Test Service-to-Service Communication
${service_payload}= Create Dictionary
... iss=service-a
... aud=service-b
... scope=read:data
${service_token}= Generate JWT Token ${service_payload} ${SERVICE_SECRET}
# Validate token at receiving service
${claims_valid}= Validate JWT Claims ${service_token}
... {"iss": "service-a", "aud": "service-b"}
Should Be True ${claims_valid}
Security Testing
Test Token Security
${token}= Generate JWT Token {"user_id": 123} ${SECRET_KEY}
# Test with tampered token
${tampered_token}= Replace String ${token} . X count=1
${is_valid}= Verify JWT Token ${tampered_token} ${SECRET_KEY}
Should Be Equal ${is_valid} ${False}
# Test token expiration
${expired_token}= Generate JWT Token {"user_id": 123} ${SECRET_KEY}
... expiration_hours=0.001
Sleep 1s
${exp_info}= Check JWT Expiration ${expired_token}
Should Be True ${exp_info['is_expired']}
🛡️ Security Considerations
- Secret Management: Never hardcode secrets in test files
- Algorithm Validation: Always verify the algorithm matches expectations
- Expiration Checking: Validate token expiration in security tests
- Claim Validation: Verify all security-relevant claims
- Signature Verification: Always verify signatures in production scenarios
📖 Documentation
🔍 Examples
Check out the examples directory for comprehensive usage examples:
🧪 Testing
Run the test suite:
# Install development dependencies
pip install -r requirements-dev.txt
# Run unit tests
pytest tests/unit/
# Run Robot Framework tests
robot tests/robot/acceptance/
# Run all tests
make test
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file robotframework_jwtlibrary-1.0.0.tar.gz.
File metadata
- Download URL: robotframework_jwtlibrary-1.0.0.tar.gz
- Upload date:
- Size: 107.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
54023ce7242c8230c16704c2fe167261c85b077d7ebf3a09e6aa15ef4ae37100
|
|
| MD5 |
fb4c2cdb8002ff767807fc7615e7300a
|
|
| BLAKE2b-256 |
112e504353f7fe939aa70949a61ad5471494dff5e0c7d5caced6739ff6549021
|
Provenance
The following attestation bundles were made for robotframework_jwtlibrary-1.0.0.tar.gz:
Publisher:
publish-pypi.yml on ohmrefresh/robotframework-jwtlibrary
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
robotframework_jwtlibrary-1.0.0.tar.gz -
Subject digest:
54023ce7242c8230c16704c2fe167261c85b077d7ebf3a09e6aa15ef4ae37100 - Sigstore transparency entry: 270337261
- Sigstore integration time:
-
Permalink:
ohmrefresh/robotframework-jwtlibrary@75af9c8b327ad5ff48fa3170dd4040f59bdaf8ae -
Branch / Tag:
refs/tags/1.0 - Owner: https://github.com/ohmrefresh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@75af9c8b327ad5ff48fa3170dd4040f59bdaf8ae -
Trigger Event:
release
-
Statement type:
File details
Details for the file robotframework_jwtlibrary-1.0.0-py3-none-any.whl.
File metadata
- Download URL: robotframework_jwtlibrary-1.0.0-py3-none-any.whl
- Upload date:
- Size: 25.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d8b4f54f8a6b8edd4a6522eac66a10a13a43004ba757f909f73148c9b95736b
|
|
| MD5 |
499da46d1fa826e570c890f9d5b6dd0e
|
|
| BLAKE2b-256 |
fdcd61834b110a7c98a122eac08c26be1014296b6089207ec5128536525d7936
|
Provenance
The following attestation bundles were made for robotframework_jwtlibrary-1.0.0-py3-none-any.whl:
Publisher:
publish-pypi.yml on ohmrefresh/robotframework-jwtlibrary
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
robotframework_jwtlibrary-1.0.0-py3-none-any.whl -
Subject digest:
2d8b4f54f8a6b8edd4a6522eac66a10a13a43004ba757f909f73148c9b95736b - Sigstore transparency entry: 270337274
- Sigstore integration time:
-
Permalink:
ohmrefresh/robotframework-jwtlibrary@75af9c8b327ad5ff48fa3170dd4040f59bdaf8ae -
Branch / Tag:
refs/tags/1.0 - Owner: https://github.com/ohmrefresh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@75af9c8b327ad5ff48fa3170dd4040f59bdaf8ae -
Trigger Event:
release
-
Statement type: