test: Add integration tests with Mock NITRO API for Issue #12#13
Open
slauger wants to merge 4 commits into
Open
test: Add integration tests with Mock NITRO API for Issue #12#13slauger wants to merge 4 commits into
slauger wants to merge 4 commits into
Conversation
Implemented a Flask-based mock of the NetScaler NITRO API to enable testing without requiring a real NetScaler appliance. Features: - NITRO authentication with X-NITRO-USER/PASS headers - Certificate management endpoints (add, update, get) - Chain certificate linking/unlinking - Proper error codes and messages matching real NetScaler - Issue #12 simulation: Prevents linking to multiple chains Files added: - tests/mock_nitro/server.py: Flask server with all endpoints - tests/mock_nitro/state.py: In-memory state management - tests/mock_nitro/README.md: Documentation and usage - tests/test_chain_rotation.py: Tests for Issue #12 scenario - requirements-dev.txt: Development dependencies All tests passing (4/4): - test_chain_rotation_without_unlink_fails ✓ - test_chain_rotation_with_unlink_succeeds ✓ - test_link_is_idempotent ✓ - test_authentication_required ✓ This enables local testing and CI/CD without NetScaler hardware.
…cking This commit adds end-to-end integration tests that run the complete plugin against the Mock NITRO API server to verify real-world scenarios. Changes: - Add tests/test_integration.py with 6 integration tests covering: * Initial certificate installation (fresh NetScaler) * Certificate renewal with same chain * Idempotent runs (no changes needed) * Chain certificate rotation (E6 → E7) for Issue #12 * Authentication error handling * Custom chain name override - Enhanced Mock NITRO API (tests/mock_nitro/): * Store uploaded certificate files in memory * Automatically extract serial numbers from uploaded PEM certificates * Serial number tracking for renewal detection * Realistic certificate state management The mock server now parses uploaded certificate files using PyOpenSSL to extract serial numbers, simulating NetScaler's behavior. This enables accurate testing of certificate renewal scenarios where the plugin compares serial numbers to detect changes. Test for Issue #12 (chain rotation) is included but skipped until the feature is implemented. It demonstrates the expected behavior: 1. Detect main cert is linked to old chain (E6) 2. Unlink from old chain 3. Install new chain certificate (E7) 4. Link to new chain All tests pass: 24 passed, 1 skipped 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
The new integration tests require pytest and other dev dependencies (Flask, requests, etc.) which are defined in requirements-dev.txt. Changes: - Install requirements-dev.txt in addition to requirements.txt - Use 'pytest tests/ -v' instead of 'unittest discover' - This enables pytest-based tests (test_chain_rotation.py, test_integration.py) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Previously, tests used fixed ports (5555, 5556) which caused 'Address already in use' exceptions when Flask server threads didn't clean up fast enough between tests. This resulted in noisy test output with many thread exceptions. Changes: - Mock server fixtures now find a free port dynamically using socket.bind() - Each test gets its own unique port, preventing conflicts - Test output is now clean with no OSError exceptions Test results: 24 passed, 1 skipped, 1 warning (down from 9 warnings) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds comprehensive integration tests with a fully functional Mock NITRO API server, enabling end-to-end testing without requiring a real NetScaler appliance.
Motivation
Related to #12 - Chain certificate rotation tracking
To implement and test the chain rotation feature (#12), we need:
What's New
Integration Tests (
tests/test_integration.py)Six comprehensive end-to-end tests covering:
--chainparameterEnhanced Mock NITRO API
The mock server has been significantly improved:
New Capabilities:
Key Implementation (
tests/mock_nitro/state.py):This enables the mock to behave like a real NetScaler, automatically extracting and storing serial numbers when certificates are uploaded and installed.
Chain Rotation Test (Issue #12)
The test
test_chain_rotation_issue_12demonstrates the expected workflow:This test is currently skipped (not implemented yet), but provides a clear specification for the chain rotation feature.
Test Results
All existing tests still pass:
Technical Details
Certificate Serial Number Tracking:
The mock API now accurately simulates NetScaler's serial number handling:
systemfileendpoint, it's storedsslcertkeyendpoint, the serial is extracted from the uploaded fileFixtures Used:
mock_server- Flask server running in background threadtemp_certs- Real X.509 certificates generated with PyOpenSSLenv_vars- Environment variables for NITRO API connectionNext Steps
This PR provides the testing infrastructure for implementing #12. Once merged, the chain rotation feature can be developed with confidence, knowing that comprehensive tests are in place.
Checklist
🤖 Generated with Claude Code