microcks / microcks/microcks-cli

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

Aperta
#486 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

stale
Lingua principale
Go
Stelle
52
Fork
68
Merge medio
6h 54m
PR unite (30g)
10

Descrizione

### 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
```

---

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia in pkg/connectors/microcks_client.go, in refreshAuthToken, e verifica come viene analizzata la scadenza dei JWT e come vengono effettuate le richieste di refresh. Usa un server Keycloak simulato con httptest per coprire i casi di token nuovi, prossimi alla scadenza, scaduti e di refresh token scaduti. Il lavoro è completato quando il comportamento di refresh previsto è verificato e i nuovi token vengono salvati nel YAML di configurazione locale, segnalando la necessità di effettuare nuovamente il login quando richiesto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
go
Ambito
authentication, cli, testing
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Attiva
Chiarezza
Abbastanza chiara
Idoneità per principianti
72/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.