Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
41ad797
feat: add jwtinfo command
xenOs76 Mar 16, 2026
dc24db7
chore: deps update
xenOs76 Mar 16, 2026
a4d0cf9
ci: add devenv tests for jwtinfo
xenOs76 Mar 16, 2026
4d63db4
ci: jwtinfo test creds via env
xenOs76 Mar 17, 2026
52ca5d8
ci: comment out file checks in devenv shell
xenOs76 Mar 17, 2026
bdff950
ci: add git-hook input to devenv
xenOs76 Mar 17, 2026
bd62c08
ci: codeChecks workflow continue on test coverage fail
xenOs76 Mar 17, 2026
811914b
ci: comment jwtinfo tests in devenv
xenOs76 Mar 17, 2026
111761e
fix: base64 decoding, linting
xenOs76 Mar 17, 2026
841ed64
ci: report fails from test coverage on main only
xenOs76 Mar 17, 2026
5a56ffa
fix: check type when extracting time claims
xenOs76 Mar 17, 2026
bcd3f65
ci: refine file input checks and webserver reponses
xenOs76 Mar 17, 2026
1c59677
fix: remove unused struct
xenOs76 Mar 17, 2026
d2c3c6b
ci: devenv test
xenOs76 Mar 17, 2026
b9fbf2f
test: ci pipeline break
xenOs76 Mar 17, 2026
075fba9
test: split devenv shell commands
xenOs76 Mar 17, 2026
72e4ef0
test: remove pipeline break
xenOs76 Mar 17, 2026
784ade4
test: run build in a separate ci step
xenOs76 Mar 17, 2026
48a947f
test: install-nix-action use nixpkgs stable
xenOs76 Mar 17, 2026
414cee3
test: add stable nixpath to devenv install step in ci
xenOs76 Mar 17, 2026
46ce155
ci: disble devenv related tests for Github actions
xenOs76 Mar 19, 2026
14a1662
ci: add tests for DecodeBase64, PrintTokenInfo and unmarshallTokenTim…
xenOs76 Mar 21, 2026
56b762f
Merge branch 'main' into feat/add_jwtinfo
xenOs76 Mar 21, 2026
efc39b2
refactor: check on token elements lenght and context in ParseTokenData
xenOs76 Mar 21, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 53 additions & 47 deletions .github/workflows/codeChecks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,34 @@ jobs:
go-package: ./...
work-dir: .

devenv_test:
needs: go_tests
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v5

- uses: cachix/install-nix-action@v31
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}

- uses: cachix/cachix-action@v16
with:
name: devenv

- name: Install devenv.sh
run: nix profile add nixpkgs#devenv

- name: Build the devenv shell and run tests
run: devenv test
timeout-minutes: 15

# # WARN this action will install devenv 2.x.x while
# # the repo still uses 1.11.1. Disabling it until devenv is upgraded
# devenv_test:
# needs: go_tests
# runs-on: ubuntu-latest
#
# steps:
# - name: Checkout
# uses: actions/checkout@v5
#
# - uses: cachix/install-nix-action@v31
# with:
# github_access_token: ${{ secrets.GITHUB_TOKEN }}
# nix_path: nixpkgs=channel:nixos-25.11
#
# - uses: cachix/cachix-action@v16
# with:
# name: devenv
#
# - name: Install devenv.sh
# run: nix profile add nixpkgs#devenv
#
# - name: Build the devenv shell and run any pre-commit hooks
# env:
# JWTINFO_TEST_AUTH0: ${{ secrets.JWTINFO_TEST_AUTH0 }}
# run: devenv test
# timeout-minutes: 15
#
go_test_coverage_check:
needs: go_tests
runs-on: ubuntu-latest
Expand All @@ -82,33 +87,34 @@ jobs:
run: go test ./... -coverprofile=./cover.out -covermode=atomic -coverpkg=./...

- name: check test coverage
continue-on-error: ${{ github.ref_name != 'main' }}
uses: vladopajic/go-test-coverage@v2
with:
config: ./.testcoverage.yml
git-token: ${{ github.ref_name == 'main' && secrets.GITHUB_TOKEN || '' }}
git-branch: badges

goreleaser_test:
needs: devenv_test
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v5
with:
fetch-depth: 0

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: "1.25"

- name: Run GoReleaser test
uses: goreleaser/goreleaser-action@v6
with:
version: "~> 2"
args: release --snapshot --clean
workdir: .
# goreleaser_test:
# needs: devenv_test
# runs-on: ubuntu-latest
#
# steps:
# - name: Checkout
# uses: actions/checkout@v5
# with:
# fetch-depth: 0
#
# - name: Set up QEMU
# uses: docker/setup-qemu-action@v3
#
# - name: Set up Go
# uses: actions/setup-go@v6
# with:
# go-version: "1.25"
#
# - name: Run GoReleaser test
# uses: goreleaser/goreleaser-action@v6
# with:
# version: "~> 2"
# args: release --snapshot --clean
# workdir: .
3 changes: 1 addition & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ linters:
enable-all-rules: true
severity: warning
rules:

# https://github.com/mgechev/revive/blob/HEAD/RULES_DESCRIPTIONS.md#add-constant
- name: add-constant
severity: warning
Expand All @@ -45,7 +44,7 @@ linters:
severity: warning
disabled: false
exclude: [""]
arguments: [100]
arguments: [120]

# https://github.com/mgechev/revive/blob/HEAD/RULES_DESCRIPTIONS.md#cognitive-complexity
- name: cognitive-complexity
Expand Down
112 changes: 112 additions & 0 deletions cmd/jwtinfo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
Copyright © 2026 Zeno Belli <xeno@os76.xyz>
*/

package cmd

import (
"fmt"
"io"
"net/http"
"os"

"github.com/MicahParks/keyfunc/v3"
"github.com/spf13/cobra"
"github.com/xenos76/https-wrench/internal/jwtinfo"
)

var (
flagNameRequestJSONValues = "request-values-json"
flagNameRequestURL = "request-url"
flagNameJwksURL = "validation-url"
requestJSONValues string
requestURL string
jwksURL string
keyfuncDefOverride keyfunc.Override
)

var jwtinfoCmd = &cobra.Command{
Use: "jwtinfo",
Short: "Request and display JWT token data",
Long: `Request and display JWT token data.`,
Run: func(cmd *cobra.Command, args []string) {
var err error
client := &http.Client{}
requestValuesMap := make(map[string]string)

if requestJSONValues != "" {
requestValuesMap, err = jwtinfo.ParseRequestJSONValues(
requestJSONValues,
requestValuesMap,
)
if err != nil {
fmt.Printf(
"error while parsing request's values JSON string: %s",
err,
)
return
}
}

tokenData, err := jwtinfo.RequestToken(
requestURL,
requestValuesMap,
client,
io.ReadAll,
)
if err != nil {
fmt.Printf("error while requesting token data: %s\n", err)
return
}

err = tokenData.DecodeBase64()
if err != nil {
fmt.Printf("DecodeBase64 error: %s\n", err)
return
}

// TODO: turn into method
token, err := jwtinfo.ParseTokenData(tokenData, jwksURL, keyfuncDefOverride)
if err != nil {
fmt.Printf("error while parsing token data: %s\n", err)
return
}

fmt.Printf("Token valid: %v\n", token.Valid)

err = jwtinfo.PrintTokenInfo(tokenData, os.Stdout)
if err != nil {
fmt.Printf("error while printing token data: %s\n", err)
return
}
},
}

func init() {
rootCmd.AddCommand(jwtinfoCmd)

jwtinfoCmd.Flags().StringVar(
&requestURL,
flagNameRequestURL,
"",
"HTTP address to use for the JWT token request",
)

jwtinfoCmd.Flags().StringVar(
&requestJSONValues,
flagNameRequestJSONValues,
"",
"JSON encoded values to use for the JWT token request",
)

jwtinfoCmd.Flags().StringVar(
&jwksURL,
flagNameJwksURL,
"",
"Url of the JSON Web Key Set (JWKS) to use for validating the JWT token",
)

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// jwtinfoCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
75 changes: 54 additions & 21 deletions devenv.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"devenv": {
"locked": {
"dir": "src/modules",
"lastModified": 1766843567,
"lastModified": 1772483048,
"owner": "cachix",
"repo": "devenv",
"rev": "d0f2c8545f09e5aba9d321079a284b550371879d",
"rev": "40f410e3a5e0f9198cf67bfa8673c9a17d8c605c",
"type": "github"
},
"original": {
Expand All @@ -19,14 +19,14 @@
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1766661267,
"owner": "edolstra",
"lastModified": 1767039857,
"owner": "NixOS",
"repo": "flake-compat",
"rev": "f275e157c50c3a9a682b4c9b4aa4db7a4cd3b5f2",
"rev": "5edf11c44bc78a0d334f6334cdaf7d60d732daab",
"type": "github"
},
"original": {
"owner": "edolstra",
"owner": "NixOS",
"repo": "flake-compat",
"type": "github"
}
Expand All @@ -35,15 +35,13 @@
"inputs": {
"flake-compat": "flake-compat",
"gitignore": "gitignore",
"nixpkgs": [
"nixpkgs"
]
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 1765911976,
"lastModified": 1772024342,
"owner": "cachix",
"repo": "git-hooks.nix",
"rev": "b68b780b69702a090c8bb1b973bab13756cc7a27",
"rev": "6e34e97ed9788b17796ee43ccdbaf871a5c2b476",
"type": "github"
},
"original": {
Expand Down Expand Up @@ -74,25 +72,42 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1764580874,
"owner": "cachix",
"repo": "devenv-nixpkgs",
"rev": "dcf61356c3ab25f1362b4a4428a6d871e84f1d1d",
"lastModified": 1773597492,
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "a07d4ce6bee67d7c838a8a5796e75dff9caa21ef",
"type": "github"
},
"original": {
"owner": "cachix",
"ref": "rolling",
"repo": "devenv-nixpkgs",
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-src": {
"flake": false,
"locked": {
"lastModified": 1769922788,
"narHash": "sha256-H3AfG4ObMDTkTJYkd8cz1/RbY9LatN5Mk4UF48VuSXc=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "207d15f1a6603226e1e223dc79ac29c7846da32e",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-stable": {
"locked": {
"lastModified": 1766736597,
"lastModified": 1772047000,
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "f560ccec6b1116b22e6ed15f4c510997d99d5852",
"rev": "1267bb4920d0fc06ea916734c11b0bf004bbe17e",
"type": "github"
},
"original": {
Expand All @@ -102,11 +117,29 @@
"type": "github"
}
},
"nixpkgs_2": {
"inputs": {
"nixpkgs-src": "nixpkgs-src"
},
"locked": {
"lastModified": 1770434727,
"owner": "cachix",
"repo": "devenv-nixpkgs",
"rev": "8430f16a39c27bdeef236f1eeb56f0b51b33d348",
"type": "github"
},
"original": {
"owner": "cachix",
"ref": "rolling",
"repo": "devenv-nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"devenv": "devenv",
"git-hooks": "git-hooks",
"nixpkgs": "nixpkgs",
"nixpkgs": "nixpkgs_2",
"nixpkgs-stable": "nixpkgs-stable",
"pre-commit-hooks": [
"git-hooks"
Expand Down
Loading
Loading