Skip to content

Commit 3e7ab0e

Browse files
Merge branch 'main' into adding-lint-commit-and-husky-to-root-configuration
Signed-off-by: Dibyanshu Pal Kushwaha <dibyanshupkushwaha@gmail.com>
2 parents e062913 + 85e434d commit 3e7ab0e

File tree

65 files changed

+4736
-3515
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+4736
-3515
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Build and upload embedded binaries
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
buildBranch:
7+
description: 'Headlamp ref/branch/tag'
8+
required: true
9+
default: 'main'
10+
version:
11+
description: 'Version for the binaries (defaults to app/package.json version)'
12+
required: false
13+
default: ''
14+
15+
permissions:
16+
contents: read
17+
18+
jobs:
19+
build-embedded:
20+
permissions:
21+
actions: write # needed to upload artifacts
22+
contents: read
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
26+
with:
27+
ref: ${{ github.event.inputs.buildBranch }}
28+
- name: Setup nodejs
29+
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
30+
with:
31+
node-version: 20.x
32+
cache: 'npm'
33+
cache-dependency-path: |
34+
frontend/package-lock.json
35+
- uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
36+
with:
37+
go-version: '1.24.*'
38+
cache-dependency-path: |
39+
backend/go.sum
40+
- name: Get version
41+
id: get-version
42+
run: |
43+
if [ -n "${{ github.event.inputs.version }}" ]; then
44+
VERSION="${{ github.event.inputs.version }}"
45+
else
46+
VERSION=$(node -p "require('./app/package.json').version")
47+
fi
48+
echo "version=$VERSION" >> $GITHUB_OUTPUT
49+
echo "Building embedded binaries with version: $VERSION"
50+
- name: Build frontend
51+
run: |
52+
make frontend
53+
- name: Prepare backend for embedding
54+
run: |
55+
make backend-embed-prepare
56+
- name: Build embedded binaries
57+
run: |
58+
make backend-embed-all-compressed VERSION=${{ steps.get-version.outputs.version }}
59+
- name: Upload embedded binaries
60+
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
61+
with:
62+
name: embedded-binaries
63+
path: ./backend/dist/*.tar.gz
64+
if-no-files-found: error
65+
retention-days: 2
66+

.github/workflows/backend-test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ jobs:
7676
rm ~/.config/Headlamp/kubeconfigs/config
7777
shell: bash
7878

79+
- name: Run fuzz tests
80+
run: npm run backend:fuzz
81+
shell: bash
82+
7983
- name: Upload coverage report as artifact
8084
id: upload-artifact
8185
uses: actions/upload-artifact@84480863f228bb9747b473957fcc9e309aa96097 # v4.4.2

.github/workflows/draft-release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
runs-on: ubuntu-latest
2121
steps:
2222
- name: Checkout code
23-
uses: actions/checkout@v4
23+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
2424
with:
2525
fetch-depth: 0
2626

@@ -48,7 +48,7 @@ jobs:
4848
echo "EOF" >> $GITHUB_OUTPUT
4949
5050
- name: Create Release Coordination Issue
51-
uses: actions/github-script@v7
51+
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
5252
with:
5353
github-token: ${{ github.token }}
5454
script: |

.github/workflows/helm-chart-release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ jobs:
7676
with:
7777
config: .github/cr.yaml
7878
mark_as_latest: false # only headlamp is set to latest
79+
skip_existing: true # skip package upload if release already exists
7980

8081
- name: Push Charts to GHCR
8182
run: |

AGENTS.md

Lines changed: 383 additions & 0 deletions
Large diffs are not rendered by default.

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ backend-embed-linux-386:
194194
backend-test:
195195
cd backend && go test -v -p 1 ./...
196196

197+
.PHONY: backend-fuzz
198+
backend-fuzz:
199+
npm run backend:fuzz
200+
197201
.PHONY: backend-coverage
198202
backend-coverage:
199203
cd backend && go test -v -p 1 -coverprofile=coverage.out ./...

OWNERS_ALIASES

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ aliases:
33
- joaquimrocha
44
- illume
55
- sniok
6+
- yolossn
67
headlamp-reviewers:
78
- joaquimrocha
89
- illume
910
- sniok
1011
- ashu8912
11-
- yolossn
1212
- vyncent-t
1313
- skoeva

app/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
"copy-plugins": "npx --no-install shx rm -rf build/.plugins && mkdirp build/.plugins && copyfiles ../.plugins build/.plugins",
1717
"dev": "npm run compile-electron && cross-env ELECTRON_DEV=1 electron .",
1818
"dev-only-app": "npm run compile-electron && cross-env ELECTRON_DEV=1 ELECTRON_START_URL=http://localhost:3000 EXTERNAL_SERVER=true electron .",
19+
"format": "cd .. && npm run frontend:format",
1920
"i18n": "npx --no-install i18next ./electron/main.ts -c ./electron/i18next-parser.config.js",
21+
"lint": "cd .. && npm run frontend:lint",
22+
"lint-fix": "cd .. && npm run frontend:lint:fix",
2023
"package": "npm run build && electron-builder build --publish never",
2124
"package-msi": "npm run build && node windows/msi/build.js",
2225
"prod-deps": "mkdirp prod_deps && cd ./prod_deps && copyfiles -f ../package.json ../package-lock.json . && npm i --only=prod && cd .. && npx --no-install shx rm -rf ./prod_deps/node_modules/.bin",
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
Copyright 2025 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package auth_test
18+
19+
import (
20+
"regexp"
21+
"testing"
22+
"unicode/utf8"
23+
24+
"github.com/kubernetes-sigs/headlamp/backend/pkg/auth"
25+
)
26+
27+
// FuzzSanitizeClusterName tests the SanitizeClusterName function with various inputs
28+
// to ensure it handles edge cases, special characters, and maintains its invariants.
29+
func FuzzSanitizeClusterName(f *testing.F) {
30+
// Seed corpus with known interesting test cases
31+
f.Add("my-cluster")
32+
f.Add("my_cluster")
33+
f.Add("cluster123")
34+
f.Add("my-cluster@#$%")
35+
f.Add("")
36+
f.Add("very-long-cluster-name-that-exceeds-fifty-characters-limit")
37+
f.Add("special!@#$%^&*()chars")
38+
f.Add("unicode-日本語-cluster")
39+
f.Add("spaces in name")
40+
f.Add("trailing-dash-")
41+
f.Add("-leading-dash")
42+
f.Add("___underscores___")
43+
f.Add("UPPERCASE")
44+
f.Add("MixedCase123")
45+
46+
validCharsRegex := regexp.MustCompile(`^[a-zA-Z0-9\-_]*$`)
47+
48+
f.Fuzz(func(t *testing.T, input string) {
49+
result := auth.SanitizeClusterName(input)
50+
51+
// Invariant 1: Result should never be longer than 50 characters
52+
if len(result) > 50 {
53+
t.Errorf("SanitizeClusterName(%q) returned result with length %d, expected <= 50", input, len(result))
54+
}
55+
56+
// Invariant 2: Result should only contain alphanumeric characters, hyphens, and underscores
57+
if !validCharsRegex.MatchString(result) {
58+
t.Errorf("SanitizeClusterName(%q) = %q contains invalid characters", input, result)
59+
}
60+
61+
// Invariant 3: Result should be a valid UTF-8 string
62+
if !utf8.ValidString(result) {
63+
t.Errorf("SanitizeClusterName(%q) = %q is not valid UTF-8", input, result)
64+
}
65+
66+
// Invariant 4: If input is empty, result should be empty
67+
if input == "" && result != "" {
68+
t.Errorf("SanitizeClusterName(%q) = %q, expected empty string", input, result)
69+
}
70+
71+
// Invariant 5: Result should be idempotent - sanitizing the result again should give the same result
72+
result2 := auth.SanitizeClusterName(result)
73+
if result != result2 {
74+
t.Errorf("SanitizeClusterName is not idempotent: first=%q, second=%q", result, result2)
75+
}
76+
77+
// Invariant 6: Result length should never exceed input length (sanitization only removes characters)
78+
if len(input) > 0 && len(result) > len(input) {
79+
t.Errorf("SanitizeClusterName(%q) returned result longer than input: input_len=%d, result_len=%d",
80+
input, len(input), len(result))
81+
}
82+
})
83+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
go test fuzz v1
2+
string("my-cluster@#$%")

0 commit comments

Comments
 (0)