How SapMock Works
A comprehensive guide to understanding the architecture, capabilities, and limitations of SapMock.
What is SapMock?
SapMock is a standalone HTTP proxy server that intercepts requests to SAP OData services and returns realistic mock data based on the service's metadata schema.
It sits between your application and your SAP system, allowing you to develop and test SAP integrations without depending on live SAP environments.
Think of it as a "smart proxy" that learns your SAP service structure and automatically generates type-correct, realistic mock responses.
How Does It Work?
Proxy Interception
Your application makes OData requests to SapMock instead of directly to SAP:
SapMock intercepts all requests matching the pattern /sap/opu/odata/*
Metadata Discovery (Two Ways)
SapMock supports two methods for loading metadata:
Option 1: Automatic Fetching from SAP
- On first request, fetches
$metadatafrom your real SAP system - Parses EDMX and caches indefinitely
- Requires SAP connection + authentication
Option 2: POST EDMX Directly
- Send EDMX XML in POST/PUT request body (Content-Type: application/xml or text/xml)
- SapMock parses and caches it for that service path
- No SAP connection needed - works completely offline!
What gets extracted: Entity types, properties, EDM data types, navigation properties, complex types, and relationships.
Entity Matching & Routing
SapMock uses 11 intelligent matching strategies (executed in order) to find the correct entity:
Result: Entity resolution is highly resilient - the multi-strategy approach maximizes match success even with naming variations.
Mock Data Generation
SapMock generates realistic, type-correct mock data using the Bogus library with intelligent heuristics:
/Date(timestamp)/)Important: Mock data is generated on-the-fly for each request. No state is maintained between requests (stateless design).
OData Response Formatting
The generated mock data is formatted as a proper OData response:
Includes proper __metadata fields, OData V2/V3/V4 envelope formats, and correct MIME types.
Authentication & Security
Two Authentication Modes
SapMock supports two flexible authentication modes with automatic fallback, giving you complete control over how credentials are managed.
Header Forwarding (Recommended)
Authentication headers from your requests are transparently forwarded to SAP. No credentials stored in SapMock.
- Zero-trust security - No credentials stored in SapMock
- User-specific data - Each developer uses their own SAP credentials
- Works with any auth - OAuth, Basic, Bearer tokens, SAML, or custom headers
Forwarded headers: Authorization, sap-client, and sap-language. These headers are forwarded to SAP when fetching metadata.
Configured Credentials (Fallback)
If no Authorization header is present, SapMock falls back to configured credentials.
- →Useful for shared CI/CD environments with a dedicated mock SAP account
- →Credentials are optional - header forwarding works without them
Security Warning: Never commit credentials to source control. Use environment variables or secret managers (Azure Key Vault, AWS Secrets Manager).
X-CSRF-Token Handling
SapMock includes automatic X-CSRF-Token generation to satisfy SAP client libraries that require these tokens.
How It Works
- 1.When a request includes
x-csrf-token: fetchheader, SapMock generates a random Base64 token (32 bytes, SAP-style format) - 2.The token is returned in the response header:
x-csrf-token: [generated-token] - 3.If no
x-csrf-tokenheader exists in the response, SapMock automatically adds one to every response - 4.Tokens are NOT validated - SapMock accepts any token value since responses are stateless mocks
Why this matters: Many SAP OData clients (SAP UI5, SAP Cloud SDK) automatically fetch CSRF tokens before making write requests. SapMock generates these tokens so client libraries work without modification, even though SapMock doesn't actually accept write operations.
What SapMock Supports
Supported Features
- ✓Automatic metadata fetching from SAP $metadata endpoint
- ✓POST/PUT EDMX XML in request body for offline use (no SAP connection required)
- ✓$metadata requests (returns cached EDMX XML)
- ✓Entity collections (e.g.,
/ProductSet) - ✓Single entity by key (e.g.,
/ProductSet('001')) - ✓OData V2, V3, and V4 protocol versions
- ✓Complex types and nested structures
- ✓Navigation properties (generated recursively)
- ✓Header forwarding (Authorization, sap-client, sap-language)
- ✓X-CSRF-Token generation for SAP client compatibility
⚠NOT Supported (By Design)
- ✗Query parameters ($filter, $select, $expand, $skip, $top, $orderby)
- ✗State management (no data persistence between requests)
- ✗POST/PUT/PATCH/DELETE operations (read-only mock)
- ✗Function imports or custom operations
- ✗Batch requests ($batch endpoint)
- ✗Recording/replay functionality
- ✗User-defined responses or custom mock data
Why? SapMock is designed for fast, stateless metadata-based mocking only. Query parameters and state management would require a database and complex query engine.
Ideal Use Cases
✅ Perfect For
- Backend integration tests that verify entity structures and data types
- CI/CD pipelines where SAP is unavailable or unreliable
- Local development without VPN or SAP access
- Contract testing to ensure your code handles OData responses correctly
- Learning OData without setting up a real SAP system
❌ NOT Suitable For
- Testing query logic ($filter, $select, pagination)
- Testing CRUD operations (create, update, delete)
- Validating business logic in SAP (e.g., price calculations, stock checks)
- Load testing SAP-specific performance
- Replacing a full SAP sandbox for end-to-end testing
Quick Start Example
1. Start SapMock with Docker
2. Point your app to SapMock
3. Make requests as usual
That's it!
No configuration files, no manual JSON responses, no complex setup. SapMock learns from your SAP metadata and just works.
Production Deployment
SapMock.Service can be deployed anywhere: Docker, Kubernetes, Azure, AWS, on-premises, or integrated into your CI/CD pipeline. Choose the deployment method that fits your infrastructure.
Docker
Run as a container (recommended for production)
Using docker run
Using docker-compose.yml
Kubernetes
Deploy to any Kubernetes cluster (AKS, EKS, GKE, on-premises)
1. Create Secret for License Key
2. Create Deployment
3. Deploy
Standalone Binary
Run without Docker on Windows, Linux, or macOS
Download Binaries
Download the latest release:
Download Page• Windows: sapmock-service-{version}-win-x64.zip
• Linux (x64): sapmock-service-{version}-linux-x64.tar.gz
• Linux (ARM): sapmock-service-{version}-linux-arm64.tar.gz
• macOS (Intel): sapmock-service-{version}-osx-x64.tar.gz
• macOS (M1/M2): sapmock-service-{version}-osx-arm64.tar.gz
Linux/macOS
Windows
Linux Systemd Service
Environment Variables Reference
| Variable | Required | Description | Example |
|---|---|---|---|
| SAPMOCK_LICENSE | Yes | Your license key from trial or subscription | SAPMOCK-DEV-... |
| Sap__Host | Optional* | SAP server URL (protocol + host + port only) | https://sap.company.com:8000 |
| Sap__Username | No | Fallback SAP username (if not using header forwarding) | MOCKUSER |
| Sap__Password | No | Fallback SAP password (if not using header forwarding) | •••••••• |
| Sap__Client | No | SAP client number | 100 |
| Sap__ValidateSsl | No | Validate SAP server SSL certificate | true |
| ASPNETCORE_URLS | No | Server listening URL | http://+:5000 |
*Note on Sap__Host: Only required if automatically fetching metadata from SAP. If you POST EDMX directly in request bodies, SapMock works completely offline without SAP connection.
Cloud Platform Deployment
SapMock.Service can be deployed to any cloud platform that supports Docker or .NET applications.
Azure
- • Azure App Service (Web App for Containers)
- • Azure Container Instances (ACI)
- • Azure Kubernetes Service (AKS)
AWS
- • AWS Elastic Container Service (ECS)
- • AWS Fargate
- • AWS Elastic Kubernetes Service (EKS)
- • AWS Elastic Beanstalk
Google Cloud
- • Google Cloud Run
- • Google Kubernetes Engine (GKE)
- • Compute Engine
On-Premises
- • Docker / Podman
- • Kubernetes / OpenShift
- • Linux systemd service
- • Windows Service (NSSM)
Key principle: SapMock.Service is 100% offline - it never communicates with our servers. Deploy it in air-gapped networks, private VNets, or anywhere you need complete isolation.