microcks / microcks/microcks-cli
Missing Verification for Automatic OIDC Access Token Refreshing and JWT Expiration Claim Parsing
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 52
- Forks
- 68
- Merge medio
- 6 h 54 min
- PR fusionados (30 d)
- 10
Descripción
### 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
```
---
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza en pkg/connectors/microcks_client.go, en refreshAuthToken, e inspecciona cómo se analiza la expiración de JWT y cómo se realizan las solicitudes de refresh. Usa un servidor Keycloak simulado con httptest para cubrir los casos de tokens nuevos, próximos a expirar, expirados y refresh tokens expirados. Se considera terminado cuando se verifica el comportamiento de refresh esperado y los nuevos tokens se guardan en el YAML de configuración local, informando de que es necesario volver a iniciar sesión cuando corresponda.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- go
- Área
- authentication, cli, testing
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Activo
- Claridad
- Bastante claro
- Aptitud para principiantes
- 72/100