microcks / microcks/microcks-cli

Missing Verification for Automatic OIDC Access Token Refreshing and JWT Expiration Claim Parsing

Offen
#486 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

stale
Vorherrschende Sprache
Go
Sterne
52
Forks
68
Ø Merge
6 Std. 54 Min.
Gemergte PRs (30 T.)
10

Beschreibung

### Describe the bug

* **Location**: [pkg/connectors/microcks_client.go](file:///c:/Users/Hp/microcks-cli/pkg/connectors/microcks_client.go) -> `refreshAuthToken`
* **Detailed Description**:
When you run the CLI for a long time (like keeping it active in the background), the security token it got when you logged in will eventually expire. To prevent commands from failing, we have code that reads the cached security token, parses it to see when it expires, and automatically requests a new one from the server if it's running out of time.

Currently, we have zero tests checking this check-and-refresh logic. If a bug is introduced here, the CLI will suddenly stop working after a while and throw unauthorized errors (like HTTP 401) out of nowhere. We need to make sure the token checks are accurate and that the refresh requests are triggered correctly.
* **Test Requirements**:
* Verify that a valid, fresh token does not trigger a refresh.
* Verify that a token close to expiry or already expired triggers the refresh server call.
* Check that the CLI successfully updates the local configuration file with the new token.
* Make sure the CLI handles cases where the refresh token itself has expired and tells the user to log in again.

#### Simulation Diagram
```mermaid
sequenceDiagram
autonumber
actor Test as Test Runner
participant MC as microcksClient
participant mockKC as Mock Keycloak Server (httptest)

Test->>MC: Trigger refreshAuthToken() with Expired JWT
activate MC
MC->>MC: Parse JWT Claims & Detect Expiration (exp <= now)
Note over MC: Expiration detected. Initiating refresh flow...
MC->>mockKC: POST /protocol/openid-connect/token (refresh_token grant)
activate mockKC
mockKC-->>MC: HTTP 200 OK (New Auth & Refresh Tokens)
deactivate mockKC
MC->>MC: Save new tokens to localconfig YAML file
MC-->>Test: Success (Token Refreshed)
deactivate MC
```

---

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne in pkg/connectors/microcks_client.go bei refreshAuthToken und untersuche, wie der Ablauf von JWT abläuft und wie Refresh-Anfragen gestellt werden. Verwende einen httptest-Mock-Keycloak-Server, um Fälle für noch gültige, bald ablaufende, abgelaufene und abgelaufene Refresh-Tokens abzudecken. Als erledigt gilt die Aufgabe, wenn das erwartete Refresh-Verhalten verifiziert ist und die neuen Tokens in der lokalen Konfigurations-YAML gespeichert werden, wobei bei Bedarf eine erneute Anmeldung gemeldet wird.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
go
Bereich
authentication, cli, testing
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Aktiv
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
72/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.