-
Notifications
You must be signed in to change notification settings - Fork 0
feat(auth): enhance token validation and keyring integration #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
PerryProjects
wants to merge
1
commit into
main
Choose a base branch
from
feature/auth
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,204 @@ | ||
| # Zusammenfassung der Verbesserungen | ||
|
|
||
| ## ✅ Probleme gelöst | ||
|
|
||
| ### 1. **Rust Fehler: `const KEYRING_USER`** | ||
|
|
||
| **Problem:** | ||
| ```rust | ||
| const KEYRING_USER: &str = username().as_str(); // ❌ FEHLER | ||
| ``` | ||
| - `username()` ist keine Compile-Zeit-Konstante | ||
| - Destruktor von `String` kann nicht in Konstanten evaluiert werden | ||
|
|
||
| **Lösung:** | ||
| ```rust | ||
| use once_cell::sync::Lazy; | ||
|
|
||
| static KEYRING_USER: Lazy<String> = Lazy::new(|| username()); // ✅ RICHTIG | ||
| ``` | ||
|
|
||
| **Erklärung:** | ||
| - `Lazy<T>` evaluiert den Wert lazy zur Runtime (beim ersten Zugriff) | ||
| - `static` statt `const` erlaubt Runtime-Initialisierung | ||
| - Der Wert wird nur einmal berechnet und dann gecacht | ||
|
|
||
| ### 2. **Test `test_keyring` erfolgreich** | ||
|
|
||
| Der Test läuft jetzt erfolgreich durch: | ||
| ``` | ||
| test auth::keyring::auth_test::test_keyring ... ok | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## 🚀 Mock-Server Verbesserungen | ||
|
|
||
| Der Mock-Server wurde komplett überarbeitet mit folgenden Features: | ||
|
|
||
| ### Neue Features | ||
|
|
||
| 1. **🎲 Deterministische Mocks** | ||
| - Seed-basierte Generierung für wiederholbare Tests | ||
| - Konsistente Daten über mehrere Requests | ||
|
|
||
| 2. **🌍 Realistische GitHub-Daten** | ||
| - GitHub-ähnliche IDs (`MDQ6VXNlcjU4MzIzMQ==`) | ||
| - Realistische Namen, URLs, Repositories | ||
| - Korrekte Datenstrukturen für alle GitHub-Entitäten | ||
|
|
||
| 3. **⏱️ Netzwerk-Simulation** | ||
| - Konfigurierbare Delays (100-500ms) | ||
| - Simuliert realistische API-Latenz | ||
| - Kann für schnelle Tests deaktiviert werden | ||
|
|
||
| 4. **📝 Detailliertes Logging** | ||
| - Request/Response Tracking | ||
| - Error Logging | ||
| - Operation Names | ||
|
|
||
| 5. **🎯 Vordefinierte Szenarien** | ||
| - `standard` - Normale GitHub-Daten | ||
| - `fast` - Keine Delays für schnelle Tests | ||
| - `large` - Viele Repositories/Projekte | ||
| - `minimal` - Minimale Daten | ||
| - `slowNetwork` - Langsame Verbindung | ||
| - `errors` - Error-Testing | ||
|
|
||
| 6. **🔧 Flexible Konfiguration** | ||
| - Environment Variables | ||
| - Szenarien per Kommandozeile | ||
| - Port-Konfiguration | ||
|
|
||
| ### Verwendung | ||
|
|
||
| ```bash | ||
| # Standard-Modus | ||
| bun run start | ||
|
|
||
| # Schneller Modus (keine Delays) | ||
| bun run start:fast | ||
|
|
||
| # Großes Szenario | ||
| bun run start:large | ||
|
|
||
| # Custom Port | ||
| PORT=4001 bun run start | ||
|
|
||
| # Custom Szenario | ||
| MOCK_SCENARIO=minimal bun run start | ||
|
|
||
| # Logging deaktivieren | ||
| LOGGING=false bun run start | ||
| ``` | ||
|
|
||
| ### Neue Dateien | ||
|
|
||
| 1. **`mock-server/index.ts`** - Hauptserver mit erweiterten Features | ||
| 2. **`mock-server/scenarios.ts`** - Vordefinierte Testszenarien | ||
| 3. **`mock-server/README.md`** - Dokumentation | ||
| 4. **`mock-server/package.json`** - Scripts und Dependencies | ||
|
|
||
| ### Gemockte Entitäten | ||
|
|
||
| - ✅ User/Viewer (mit realistischen Profilen) | ||
| - ✅ Repository (mit Stats, URLs, etc.) | ||
| - ✅ Project/ProjectV2 (mit Beschreibungen) | ||
| - ✅ Issue (mit States, Timestamps) | ||
| - ✅ PullRequest (mit Merge-Status) | ||
| - ✅ Organization (mit Profilen) | ||
| - ✅ Connections (mit Pagination) | ||
|
|
||
| ### Beispiel-Output | ||
|
|
||
| ``` | ||
| 🚀 GitHub GraphQL Mock Server ready! | ||
| ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
| 📍 URL: http://localhost:4001/ | ||
| 🎯 Scenario: standard | ||
| 🎲 Seed: 12345 | ||
| ⏱️ Delay: 100-500ms | ||
| 📝 Logging: enabled | ||
| ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
|
|
||
| 💡 Tips: | ||
| • Open browser: GraphQL Playground at http://localhost:4001/ | ||
| • Change scenario: MOCK_SCENARIO=fast bun run index.ts | ||
| • Available scenarios: standard, fast, large, minimal, slowNetwork, errors | ||
| • Disable logging: LOGGING=false bun run index.ts | ||
|
|
||
| 📨 Request started: AuthCheck | ||
| ✅ Response sent: AuthCheck | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## 📚 Nützliche Commands | ||
|
|
||
| ### Rust Tests | ||
| ```bash | ||
| # Alle Tests | ||
| cargo test | ||
|
|
||
| # Nur Keyring-Test | ||
| cargo test test_keyring -- --nocapture | ||
|
|
||
| # Mit Output | ||
| cargo test -- --nocapture --test-threads=1 | ||
| ``` | ||
|
|
||
| ### Mock-Server | ||
| ```bash | ||
| # Dependencies installieren | ||
| cd mock-server && bun install | ||
|
|
||
| # Server starten | ||
| bun run start | ||
|
|
||
| # Server im Watch-Modus | ||
| bun run dev | ||
|
|
||
| # Docker | ||
| docker-compose up | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## 🎓 Lessons Learned | ||
|
|
||
| ### 1. Const vs Static in Rust | ||
| - `const` = Compile-Zeit-Konstante, inline ersetzt | ||
| - `static` = Runtime-Variable mit fixer Adresse | ||
| - Für Runtime-Funktionen: `static` + `Lazy` | ||
|
|
||
| ### 2. Mock-Server Best Practices | ||
| - Deterministische Daten (Seed) für reproduzierbare Tests | ||
| - Realistische Verzögerungen für bessere Tests | ||
| - Szenarien für verschiedene Testfälle | ||
| - Detailliertes Logging für Debugging | ||
|
|
||
| ### 3. GraphQL Mocking | ||
| - `@graphql-tools/mock` für automatisches Mocking | ||
| - Custom Resolvers für spezielle Logik | ||
| - Faker für realistische Testdaten | ||
| - State Management für Konsistenz | ||
|
|
||
| --- | ||
|
|
||
| ## ✨ Nächste Schritte | ||
|
|
||
| 1. **Rust-Seite:** | ||
| - Auth-Flow vollständig testen | ||
| - Import-Funktionalität implementieren | ||
| - Integration mit Mock-Server testen | ||
|
|
||
| 2. **Mock-Server:** | ||
| - Custom Resolvers für spezifische Queries hinzufügen | ||
| - Error-Szenarien erweitern | ||
| - Rate-Limiting simulieren | ||
|
|
||
| 3. **Integration:** | ||
| - E2E-Tests mit Mock-Server | ||
| - Performance-Tests mit verschiedenen Szenarien | ||
| - CI/CD Integration | ||
|
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
Move
wiremockto dev-dependencies.The
wiremockcrate is a testing library and should be a dev-dependency rather than a production dependency to avoid bloating the release binary.Apply this diff:
graphql_client = "0.14.0" tokio = { version = "1.48.0", features = ["macros", "rt-multi-thread"] } -wiremock = "0.6.5" serde_json = "1.0.145" + +[dev-dependencies] +wiremock = "0.6.5"🤖 Prompt for AI Agents