|
| 1 | +import sys |
| 2 | +from pathlib import Path |
| 3 | + |
| 4 | + |
| 5 | +sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "scripts")) |
| 6 | + |
| 7 | +from validate_integration import IntegrationValidator # noqa: E402 |
| 8 | + |
| 9 | + |
| 10 | +def _validate_auth(config: dict) -> IntegrationValidator: |
| 11 | + validator = IntegrationValidator(Path("custom-auth")) |
| 12 | + validator.config = config |
| 13 | + validator._validate_auth_config() |
| 14 | + return validator |
| 15 | + |
| 16 | + |
| 17 | +def test_custom_auth_without_required_is_valid() -> None: |
| 18 | + validator = _validate_auth( |
| 19 | + { |
| 20 | + "auth": { |
| 21 | + "type": "custom", |
| 22 | + "fields": { |
| 23 | + "type": "object", |
| 24 | + "properties": { |
| 25 | + "api_key": {"type": "string"}, |
| 26 | + }, |
| 27 | + }, |
| 28 | + } |
| 29 | + } |
| 30 | + ) |
| 31 | + |
| 32 | + assert validator.errors == [] |
| 33 | + assert validator.warnings == [] |
| 34 | + |
| 35 | + |
| 36 | +def test_custom_auth_empty_required_array_is_allowed() -> None: |
| 37 | + validator = _validate_auth( |
| 38 | + { |
| 39 | + "auth": { |
| 40 | + "type": "custom", |
| 41 | + "fields": { |
| 42 | + "type": "object", |
| 43 | + "properties": { |
| 44 | + "api_key": {"type": "string"}, |
| 45 | + }, |
| 46 | + "required": [], |
| 47 | + }, |
| 48 | + } |
| 49 | + } |
| 50 | + ) |
| 51 | + |
| 52 | + assert validator.errors == [] |
| 53 | + assert validator.warnings == [] |
| 54 | + |
| 55 | + |
| 56 | +def test_custom_auth_non_empty_required_array_is_rejected() -> None: |
| 57 | + validator = _validate_auth( |
| 58 | + { |
| 59 | + "auth": { |
| 60 | + "type": "custom", |
| 61 | + "fields": { |
| 62 | + "type": "object", |
| 63 | + "properties": { |
| 64 | + "api_key": {"type": "string"}, |
| 65 | + }, |
| 66 | + "required": ["api_key"], |
| 67 | + }, |
| 68 | + } |
| 69 | + } |
| 70 | + ) |
| 71 | + |
| 72 | + messages = [error.message for error in validator.errors] |
| 73 | + assert messages == [ |
| 74 | + "Custom auth fields must not define a non-empty auth.fields.required array. " |
| 75 | + "Credential collection and presence are handled by the platform connection flow; " |
| 76 | + "define auth.fields.properties only." |
| 77 | + ] |
| 78 | + assert validator.warnings == [] |
0 commit comments