validra 0.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. validra-0.1.2/LICENSE +21 -0
  2. validra-0.1.2/PKG-INFO +385 -0
  3. validra-0.1.2/README.md +358 -0
  4. validra-0.1.2/app/api/routes/generation.py +142 -0
  5. validra-0.1.2/app/api/routes/validation.py +34 -0
  6. validra-0.1.2/app/api/schemas/requests.py +159 -0
  7. validra-0.1.2/app/api/schemas/responses.py +30 -0
  8. validra-0.1.2/app/cli.py +5 -0
  9. validra-0.1.2/app/config/settings.py +21 -0
  10. validra-0.1.2/app/engine/executor.py +33 -0
  11. validra-0.1.2/app/engine/orchestrator.py +136 -0
  12. validra-0.1.2/app/main.py +95 -0
  13. validra-0.1.2/app/plugins/base.py +18 -0
  14. validra-0.1.2/app/plugins/fuzz/plugin.py +136 -0
  15. validra-0.1.2/app/plugins/llm_plugin.py +141 -0
  16. validra-0.1.2/app/plugins/pen/plugin.py +81 -0
  17. validra-0.1.2/app/plugins/registry.py +20 -0
  18. validra-0.1.2/app/plugins/security/plugin.py +58 -0
  19. validra-0.1.2/app/providers/anthropic/config.py +12 -0
  20. validra-0.1.2/app/providers/anthropic/provider.py +46 -0
  21. validra-0.1.2/app/providers/base.py +26 -0
  22. validra-0.1.2/app/providers/ollama/config.py +10 -0
  23. validra-0.1.2/app/providers/ollama/provider.py +56 -0
  24. validra-0.1.2/app/providers/openai/config.py +11 -0
  25. validra-0.1.2/app/providers/openai/provider.py +45 -0
  26. validra-0.1.2/app/providers/registry.py +20 -0
  27. validra-0.1.2/app/static/favicon.ico +0 -0
  28. validra-0.1.2/app/validator/base.py +16 -0
  29. validra-0.1.2/app/validator/llm_validator.py +122 -0
  30. validra-0.1.2/pyproject.toml +49 -0
  31. validra-0.1.2/setup.cfg +4 -0
  32. validra-0.1.2/tests/test_api.py +131 -0
  33. validra-0.1.2/tests/test_executor.py +80 -0
  34. validra-0.1.2/tests/test_llm_plugin.py +84 -0
  35. validra-0.1.2/tests/test_orchestrator.py +111 -0
  36. validra-0.1.2/tests/test_registries.py +62 -0
  37. validra-0.1.2/tests/test_validator.py +73 -0
  38. validra-0.1.2/validra.egg-info/PKG-INFO +385 -0
  39. validra-0.1.2/validra.egg-info/SOURCES.txt +41 -0
  40. validra-0.1.2/validra.egg-info/dependency_links.txt +1 -0
  41. validra-0.1.2/validra.egg-info/entry_points.txt +2 -0
  42. validra-0.1.2/validra.egg-info/requires.txt +10 -0
  43. validra-0.1.2/validra.egg-info/top_level.txt +1 -0
validra-0.1.2/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Roberto Luis Pegoraro
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
validra-0.1.2/PKG-INFO ADDED
@@ -0,0 +1,385 @@
1
+ Metadata-Version: 2.4
2
+ Name: validra
3
+ Version: 0.1.2
4
+ Summary: AI-powered API test generation and validation engine
5
+ License: MIT
6
+ Keywords: api,testing,llm,ai,fuzz,security
7
+ Classifier: Development Status :: 4 - Beta
8
+ Classifier: Intended Audience :: Developers
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Topic :: Software Development :: Testing
14
+ Requires-Python: >=3.11
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: fastapi>=0.110.0
18
+ Requires-Dist: uvicorn[standard]>=0.29.0
19
+ Requires-Dist: requests>=2.31.0
20
+ Requires-Dist: pydantic>=2.0.0
21
+ Requires-Dist: pydantic-settings>=2.0.0
22
+ Provides-Extra: dev
23
+ Requires-Dist: pytest>=8.0.0; extra == "dev"
24
+ Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
25
+ Requires-Dist: httpx>=0.27.0; extra == "dev"
26
+ Dynamic: license-file
27
+
28
+ # Validra Core
29
+
30
+ AI-powered API test generation and validation engine. Validra uses Large Language Models to automatically generate test cases — fuzzing, security, and penetration tests — and executes them against live APIs, validating responses intelligently.
31
+
32
+ ---
33
+
34
+ ## Features
35
+
36
+ - **3 test plugins**: Fuzz (edge-case inputs), Auth (header mutations), Pen (injection & privilege escalation)
37
+ - **3 LLM providers**: Ollama (local), OpenAI, Anthropic — switchable per-request
38
+ - **End-to-end pipeline**: Generate → Execute → Validate, all in one request
39
+ - **LLM-powered validation**: Responses are assessed by the LLM with PASS/FAIL/WARN + confidence score
40
+ - **Stateless API**: No database, minimal dependencies — install via `pip install validra`
41
+
42
+ ---
43
+
44
+ ## Quick Start
45
+
46
+ **Prerequisites**: Python 3.11+
47
+
48
+ ```bash
49
+ pip install validra
50
+ validra
51
+ ```
52
+
53
+ The API will be available at `http://localhost:8000`.
54
+ Swagger UI: `http://localhost:8000/docs`
55
+
56
+ Validra works out of the box with Ollama as the default provider. To use OpenAI or Anthropic instead, set your key before starting:
57
+
58
+ ```bash
59
+ OPENAI_API_KEY=sk-... validra
60
+ # or
61
+ ANTHROPIC_API_KEY=sk-ant-... validra
62
+ ```
63
+
64
+ Or create a `.env` file in the directory where you run `validra`:
65
+
66
+ ```bash
67
+ cp .env.example .env
68
+ # edit .env, then:
69
+ validra
70
+ ```
71
+
72
+ > **Using Ollama?** Install it from [ollama.ai](https://ollama.ai) and run `ollama serve`. Validra connects to it automatically — no extra configuration needed.
73
+
74
+ ---
75
+
76
+ ## Configuration
77
+
78
+ Validra has sensible defaults built in. Most users don't need any configuration to get started — just run it and go.
79
+
80
+ There are two ways to configure behaviour, each suited to different needs:
81
+
82
+ ### 1. Environment variables (`.env`) — persistent, server-level config
83
+
84
+ Use a `.env` file (or real environment variables) for things that are fixed for your setup:
85
+
86
+ | Variable | Default | When to set |
87
+ |---|---|---|
88
+ | `DEFAULT_PROVIDER` | `ollama` | Change if you always want OpenAI or Anthropic |
89
+ | `OLLAMA_URL` | `http://localhost:11434/api/generate` | Only if Ollama runs on a non-default address |
90
+ | `OPENAI_API_KEY` | — | Required to use the OpenAI provider |
91
+ | `ANTHROPIC_API_KEY` | — | Required to use the Anthropic provider |
92
+ | `EXECUTOR_TIMEOUT` | `60` | Increase if your target API is slow |
93
+
94
+ ```env
95
+ # Minimal .env for OpenAI users
96
+ DEFAULT_PROVIDER=openai
97
+ OPENAI_API_KEY=sk-...
98
+ ```
99
+
100
+ `.env` is completely optional. If you pass `api_key` directly in `provider_config` on each request, you don't need a `.env` file at all.
101
+
102
+ ---
103
+
104
+ ### 2. `provider_config` in the request — per-request overrides
105
+
106
+ Use `provider_config` when you want to change provider behaviour for a specific call without touching server config:
107
+
108
+ ```json
109
+ {
110
+ "provider": "openai",
111
+ "provider_config": {
112
+ "api_key": "sk-...",
113
+ "model": "gpt-4o-mini",
114
+ "temperature": 0.9,
115
+ "max_tokens": 1000,
116
+ "timeout": 30
117
+ }
118
+ }
119
+ ```
120
+
121
+ Unknown fields in `provider_config` are rejected with a `400` error.
122
+
123
+ ---
124
+
125
+ ### Provider defaults (built into code)
126
+
127
+ If neither `.env` nor `provider_config` sets a value, these defaults apply. All fields are overridable via `provider_config` in the request.
128
+
129
+ **Ollama**
130
+
131
+ | Field | Default | Description |
132
+ |---|---|---|
133
+ | `model` | `llama3:8b-instruct-q4_0` | Model identifier |
134
+ | `temperature` | `0.7` | Sampling temperature |
135
+ | `max_tokens` | `700` | Max output tokens |
136
+ | `top_p` | `0.9` | Top-p sampling |
137
+ | `url` | `http://localhost:11434/api/generate` | Ollama API endpoint |
138
+ | `timeout` | `300` | Request timeout in seconds |
139
+
140
+ **OpenAI**
141
+
142
+ | Field | Default | Description |
143
+ |---|---|---|
144
+ | `model` | `gpt-4o` | Model identifier |
145
+ | `temperature` | `0.7` | Sampling temperature |
146
+ | `max_tokens` | `700` | Max output tokens |
147
+ | `timeout` | `60` | Request timeout in seconds |
148
+ | `api_key` | — | Required (env or per-request) |
149
+ | `base_url` | `https://api.openai.com/v1/chat/completions` | API endpoint |
150
+
151
+ **Anthropic**
152
+
153
+ | Field | Default | Description |
154
+ |---|---|---|
155
+ | `model` | `claude-sonnet-4-6` | Model identifier |
156
+ | `temperature` | `0.7` | Sampling temperature |
157
+ | `max_tokens` | `700` | Max output tokens |
158
+ | `timeout` | `60` | Request timeout in seconds |
159
+ | `api_key` | — | Required (env or per-request) |
160
+ | `base_url` | `https://api.anthropic.com/v1/messages` | API endpoint |
161
+ | `anthropic_version` | `2023-06-01` | Anthropic API version header |
162
+
163
+ ---
164
+
165
+ ## API Reference
166
+
167
+ ### `POST /generateAndRun`
168
+
169
+ Generates test cases and executes them against a target API endpoint.
170
+
171
+ **Request body:**
172
+
173
+ | Field | Type | Required | Description |
174
+ |---|---|---|---|
175
+ | `endpoint` | string | yes | Target API URL |
176
+ | `method` | string | yes | `POST` or `GET` |
177
+ | `headers` | object | no | HTTP headers to send (default: `{}`) |
178
+ | `payload` | object | yes | Request body or query params |
179
+ | `payload_meta` | object | no | Field constraints for smarter test generation |
180
+ | `test_type` | string | yes | Plugin to use: `FUZZ`, `AUTH`, or `PEN` |
181
+ | `max_cases` | integer | no | Number of test cases to generate (3–100, default: 10) |
182
+ | `validate` | boolean | no | Run LLM validation on responses (default: `true`) |
183
+ | `provider` | string | no | LLM provider: `ollama`, `openai`, `anthropic` (default: `ollama`) |
184
+ | `provider_config` | object | no | Override provider settings for this request only |
185
+
186
+ **Example — Fuzz test:**
187
+
188
+ ```json
189
+ {
190
+ "endpoint": "https://your-api.com/users",
191
+ "method": "POST",
192
+ "headers": { "Content-Type": "application/json" },
193
+ "payload": {
194
+ "username": "john",
195
+ "age": 25,
196
+ "email": "john@example.com"
197
+ },
198
+ "payload_meta": {
199
+ "username": "required, alphanumeric, [3-20] chars",
200
+ "age": "required, numeric, [0-120]",
201
+ "email": "required, valid email format"
202
+ },
203
+ "test_type": "FUZZ",
204
+ "max_cases": 10,
205
+ "provider": "ollama"
206
+ }
207
+ ```
208
+
209
+ **Example — Auth test:**
210
+
211
+ ```json
212
+ {
213
+ "endpoint": "https://your-api.com/protected",
214
+ "method": "GET",
215
+ "headers": { "Authorization": "Bearer valid-token-here" },
216
+ "payload": {},
217
+ "test_type": "AUTH",
218
+ "max_cases": 8
219
+ }
220
+ ```
221
+
222
+ **Example — Penetration test:**
223
+
224
+ ```json
225
+ {
226
+ "endpoint": "https://your-api.com/items",
227
+ "method": "POST",
228
+ "payload": {
229
+ "item_id": 1,
230
+ "name": "widget",
231
+ "role": "user"
232
+ },
233
+ "test_type": "PEN",
234
+ "max_cases": 15,
235
+ "provider": "openai",
236
+ "provider_config": { "model": "gpt-4o-mini", "temperature": 0.9 }
237
+ }
238
+ ```
239
+
240
+ **Response:**
241
+
242
+ ```json
243
+ {
244
+ "tests": [
245
+ {
246
+ "id": "tc-001",
247
+ "description": "Missing required field: username",
248
+ "request": {
249
+ "payload": { "username": null, "age": 25, "email": "john@example.com" },
250
+ "headers": { "Content-Type": "application/json" }
251
+ },
252
+ "response": {
253
+ "status_code": 422,
254
+ "body": { "error": "username is required" }
255
+ },
256
+ "success": false,
257
+ "duration_ms": 134,
258
+ "validation": {
259
+ "dstatus": "PASS",
260
+ "reason": "API correctly rejected missing required field with 422",
261
+ "confidence": 0.97
262
+ }
263
+ }
264
+ ],
265
+ "summary": {
266
+ "total": 10,
267
+ "success": 3,
268
+ "failed": 7,
269
+ "total_duration_ms": 1842
270
+ }
271
+ }
272
+ ```
273
+
274
+ ---
275
+
276
+ ### `POST /validate`
277
+
278
+ Validates a single test result using the LLM. Useful when you want to validate a test you already ran manually.
279
+
280
+ **Request body:**
281
+
282
+ | Field | Type | Required | Description |
283
+ |---|---|---|---|
284
+ | `test` | object | yes | The test case object |
285
+ | `response` | object | yes | The API response object |
286
+ | `meta` | object | no | Payload constraints (optional context) |
287
+ | `provider` | string | no | LLM provider to use |
288
+ | `provider_config` | object | no | Provider overrides |
289
+
290
+ **Response:**
291
+
292
+ ```json
293
+ {
294
+ "validation": {
295
+ "dstatus": "PASS",
296
+ "reason": "The API returned 401 as expected for a missing Authorization header.",
297
+ "confidence": 0.95
298
+ }
299
+ }
300
+ ```
301
+
302
+ `dstatus` values:
303
+ - `PASS` — response matches expected behavior
304
+ - `FAIL` — response does not match expected behavior
305
+ - `WARN` — ambiguous or partially correct
306
+
307
+ ---
308
+
309
+ ## Test Plugins
310
+
311
+ ### FUZZ
312
+
313
+ Generates edge-case and invalid payloads to test input validation. Uses `payload_meta` constraints to craft meaningful boundary violations:
314
+
315
+ - Missing required fields (`null` values)
316
+ - Out-of-range values (below min, above max)
317
+ - Type mismatches (string where integer expected, etc.)
318
+ - String violations (too short, too long, empty)
319
+
320
+ Best used to verify your API's input validation and error handling.
321
+
322
+ ---
323
+
324
+ ### AUTH
325
+
326
+ Mutates HTTP headers to test authentication and authorization edge cases. Payload is unchanged — only headers are modified:
327
+
328
+ - Missing `Authorization` header
329
+ - Expired or malformed tokens
330
+ - Wrong token format (Basic vs Bearer)
331
+ - Empty or invalid credentials
332
+
333
+ Best used to verify your API enforces authentication correctly.
334
+
335
+ ---
336
+
337
+ ### PEN
338
+
339
+ Generates penetration test-style payloads to probe for common vulnerabilities:
340
+
341
+ - Injection probes (SQL-like, NoSQL-like, template injection)
342
+ - Privilege escalation attempts (role manipulation, `isAdmin` flags)
343
+ - Parameter pollution (duplicate or conflicting fields)
344
+ - ID tampering (large numbers, negatives, other users' IDs)
345
+ - Encoding tricks (Unicode, escaped characters)
346
+ - Structural manipulation (arrays, nested objects, nulls)
347
+ - Boundary abuse (very long strings, extremely large numbers)
348
+
349
+ Best used to find security weaknesses in your API's logic.
350
+
351
+ ---
352
+
353
+ ## Project Structure
354
+
355
+ ```
356
+ validra-ai-core/
357
+ ├── app/
358
+ │ ├── api/
359
+ │ │ ├── routes/
360
+ │ │ │ ├── generation.py # POST /generateAndRun
361
+ │ │ │ └── validation.py # POST /validate
362
+ │ │ └── schemas/
363
+ │ │ ├── requests.py # Request models
364
+ │ │ └── responses.py # Response models
365
+ │ ├── config/
366
+ │ │ └── settings.py # Pydantic settings
367
+ │ ├── engine/
368
+ │ │ ├── executor.py # HTTP request executor
369
+ │ │ └── orchestrator.py # Generation + execution pipeline
370
+ │ ├── plugins/
371
+ │ │ ├── fuzz/plugin.py # Fuzz plugin
372
+ │ │ ├── security/plugin.py # Auth plugin
373
+ │ │ └── pen/plugin.py # Penetration test plugin
374
+ │ ├── providers/
375
+ │ │ ├── ollama/ # Ollama provider
376
+ │ │ ├── openai/ # OpenAI provider
377
+ │ │ └── anthropic/ # Anthropic provider
378
+ │ ├── validator/
379
+ │ │ └── llm_validator.py # LLM-based response validator
380
+ │ └── main.py # App factory & startup
381
+ ├── tests/ # Test suite
382
+ ├── .github/workflows/ # CI + PyPI publish
383
+ ├── requirements.txt
384
+ └── .env.example
385
+ ```