|
| 1 | +# GitHub Copilot Instructions for scitokens-cpp |
| 2 | + |
| 3 | +## Project Overview |
| 4 | + |
| 5 | +scitokens-cpp is a C++ library for creating and validating SciTokens (JWT-based authorization tokens for scientific computing). The library uses JWT-cpp for token operations and supports OIDC discovery with JWKS for public key distribution. |
| 6 | + |
| 7 | +## Building the Project |
| 8 | + |
| 9 | +### Prerequisites |
| 10 | + |
| 11 | +- CMake 3.10 or later |
| 12 | +- C++11 compatible compiler (gcc, clang) |
| 13 | +- OpenSSL 1.1.1 or later (3.0+ recommended) |
| 14 | +- libuuid |
| 15 | +- sqlite3 |
| 16 | +- jwt-cpp (included as vendor submodule) |
| 17 | + |
| 18 | +### Build Commands |
| 19 | + |
| 20 | +```bash |
| 21 | +# Create build directory |
| 22 | +mkdir -p build |
| 23 | +cd build |
| 24 | + |
| 25 | +# Configure with CMake (enable tests with -DSCITOKENS_BUILD_UNITTESTS=ON) |
| 26 | +cmake .. -DSCITOKENS_BUILD_UNITTESTS=ON |
| 27 | + |
| 28 | +# Build all targets |
| 29 | +make |
| 30 | + |
| 31 | +# Install (optional) |
| 32 | +sudo make install |
| 33 | +``` |
| 34 | + |
| 35 | +### CMake Build Options |
| 36 | + |
| 37 | +- Tests are **disabled by default** - use `-DSCITOKENS_BUILD_UNITTESTS=ON` to enable |
| 38 | +- Build produces: |
| 39 | + - `libSciTokens.so` - Main library |
| 40 | + - `scitokens-test` - Unit tests (Google Test) |
| 41 | + - `scitokens-integration-test` - Integration tests with real HTTPS server |
| 42 | + - `scitokens-generate-jwks` - JWKS generation utility |
| 43 | + - Command-line tools: `scitokens-verify`, `scitokens-create`, `scitokens-list-access`, `scitokens-test-access` |
| 44 | + |
| 45 | +## Running Tests |
| 46 | + |
| 47 | +### Unit Tests |
| 48 | + |
| 49 | +```bash |
| 50 | +cd build |
| 51 | +./scitokens-test |
| 52 | +``` |
| 53 | + |
| 54 | +Expected: 29 unit tests should pass |
| 55 | + |
| 56 | +### Integration Tests |
| 57 | + |
| 58 | +Integration tests use CTest fixtures with setup/teardown phases: |
| 59 | + |
| 60 | +```bash |
| 61 | +cd build/test |
| 62 | +ctest --output-on-failure |
| 63 | +``` |
| 64 | + |
| 65 | +Or run specific test phases: |
| 66 | +```bash |
| 67 | +ctest -R integration::setup # Start HTTPS JWKS server |
| 68 | +ctest -R integration::test # Run integration tests |
| 69 | +ctest -R integration::teardown # Stop server |
| 70 | +``` |
| 71 | + |
| 72 | +**Integration test infrastructure:** |
| 73 | +- `test/jwks_server.py` - Python HTTPS server with OIDC discovery and JWKS endpoints |
| 74 | +- `test/integration-test-setup.sh` - Generates TLS certificates and starts server |
| 75 | +- `test/integration-test-teardown.sh` - Stops server gracefully |
| 76 | +- `test/integration_test.cpp` - C++ tests using real HTTPS connections |
| 77 | + |
| 78 | +Expected: 3 integration tests should pass (total time ~1-2 seconds) |
| 79 | + |
| 80 | +### All Tests |
| 81 | + |
| 82 | +```bash |
| 83 | +cd build/test |
| 84 | +ctest --output-on-failure |
| 85 | +``` |
| 86 | + |
| 87 | +Expected: 32 total tests (29 unit + 3 integration) |
| 88 | + |
| 89 | +## Code Style |
| 90 | + |
| 91 | +- C++11 standard |
| 92 | +- Use `clang-format` for formatting (configuration in project root) |
| 93 | +- Format before committing: `clang-format -i src/*.cpp src/*.h` |
| 94 | + |
| 95 | +## Testing Infrastructure Details |
| 96 | + |
| 97 | +### JWKS Server (test/jwks_server.py) |
| 98 | + |
| 99 | +Python HTTPS server that provides: |
| 100 | +- `/.well-known/openid-configuration` - OIDC discovery document |
| 101 | +- `/oauth2/certs` - JWKS public key endpoint |
| 102 | + |
| 103 | +Server features: |
| 104 | +- HTTP/1.1 with keep-alive support |
| 105 | +- TLS 1.2+ with self-signed certificates |
| 106 | +- Graceful shutdown with SIGTERM |
| 107 | +- Logs to `build/tests/integration/server.log` |
| 108 | + |
| 109 | +### Integration Test Flow |
| 110 | + |
| 111 | +1. **Setup**: Generate EC P-256 key pair, create JWKS, generate TLS certificates, start HTTPS server |
| 112 | +2. **Test**: Create tokens, verify with JWKS discovery, test dynamic issuer enforcement |
| 113 | +3. **Teardown**: Stop server, print logs if tests failed |
| 114 | + |
| 115 | +### Debugging Integration Tests |
| 116 | + |
| 117 | +If integration tests fail: |
| 118 | +1. Check server log: `cat build/tests/integration/server.log` |
| 119 | +2. Verify server started: `cat build/tests/integration/server_ready` |
| 120 | +3. Test HTTPS manually: `curl -k https://localhost:<port>/.well-known/openid-configuration` |
| 121 | + |
| 122 | +## Key Files |
| 123 | + |
| 124 | +- `src/scitokens.cpp`, `src/scitokens.h` - Main library API |
| 125 | +- `src/generate_jwks.cpp` - JWKS generation (EC P-256 keys) |
| 126 | +- `src/scitokens_internal.cpp` - Token validation and OIDC discovery |
| 127 | +- `src/scitokens_cache.cpp` - JWKS caching |
| 128 | +- `test/integration_test.cpp` - End-to-end integration tests |
| 129 | +- `test/main.cpp` - Google Test unit tests |
| 130 | + |
| 131 | +## Development Workflow |
| 132 | + |
| 133 | +1. Make code changes |
| 134 | +2. Build: `cd build && cmake .. && make` |
| 135 | +3. Run unit tests: `./scitokens-test` |
| 136 | +4. Run integration tests: `cd test && ctest --output-on-failure` |
| 137 | +5. Format code: `clang-format -i <modified-files>` |
| 138 | +6. Commit with descriptive message |
| 139 | + |
| 140 | +## CI/CD |
| 141 | + |
| 142 | +GitHub Actions runs tests on: |
| 143 | +- Ubuntu 22.04 (OpenSSL 3.0.2) |
| 144 | +- Ubuntu 24.04 (OpenSSL 3.0.13) |
| 145 | + |
| 146 | +Integration tests verify TLS compatibility across OpenSSL versions. |
0 commit comments