Skip to content

Commit 07df69d

Browse files
committed
chore(kubernetes): fix tests and lint issues
1 parent 6426d47 commit 07df69d

4 files changed

Lines changed: 15 additions & 2 deletions

File tree

packages/k8s-client/src/client.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ interface ClientOptions {
1717
}
1818

1919
function createClient(options: ClientOptions) {
20-
const { apiEndpoint, ignoreSsl = false } = options
20+
const { apiEndpoint, ignoreSsl = false, debug = false } = options
2121
let token = options.token
2222

2323
if (!apiEndpoint || !token) {
2424
throw new Error(`Bad options: ${JSON.stringify(options, null, 4)}. Please provide apiEndpoint and token`)
2525
}
2626

2727
// Log warning when SSL verification is disabled
28-
if (ignoreSsl && options.debug === true) {
28+
if (ignoreSsl && debug === true) {
2929
console.warn(`⚠️ K8s Client: SSL certificate verification disabled for ${apiEndpoint}`)
3030
console.warn(`🔒 This should only be used in development or secure internal networks`)
3131
}
@@ -43,6 +43,8 @@ function createClient(options: ClientOptions) {
4343
}
4444

4545
return {
46+
debug,
47+
ignoreSsl,
4648
...defaultOptions,
4749
...options,
4850
headers,

packages/k8s-client/src/request.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ function request(method: string, url: string, options: RequestOptions = {}): Pro
4949

5050
// Create HTTPS agent if SSL should be ignored for HTTPS URLs
5151
let agent: https.Agent | undefined
52+
5253
if (ignoreSsl && url.startsWith("https:") && typeof window === "undefined") {
5354
agent = new https.Agent({
5455
rejectUnauthorized: false,

packages/k8s-client/test/client.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ describe("k8sClient", () => {
327327
})
328328

329329
test("should pass ignoreSsl to request when making HTTP calls", async () => {
330+
globalThis.window = undefined!
330331
const client = createClient({
331332
apiEndpoint: "https://internal-k8s.company.com",
332333
token: "test-token",
@@ -350,6 +351,7 @@ describe("k8sClient", () => {
350351
})
351352

352353
test("should allow per-request SSL override", async () => {
354+
globalThis.window = undefined!
353355
const client = createClient({
354356
apiEndpoint: "https://k8s-api.company.com",
355357
token: "test-token",

packages/k8s-client/test/request.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ describe("request", () => {
108108

109109
describe("Request Options", () => {
110110
test("provide only allowed options to fetch", async () => {
111+
globalThis.window = undefined!
111112
await request("GET", testUrl, {
112113
signal: "test" as unknown as AbortSignal,
113114
headers: { key1: "value1" },
@@ -159,6 +160,7 @@ describe("request", () => {
159160

160161
describe("SSL Ignore Functionality", () => {
161162
test("should create HTTPS agent when ignoreSsl is true for HTTPS URL", async () => {
163+
globalThis.window = undefined!
162164
await request("GET", testUrl, {
163165
ignoreSsl: true,
164166
headers: { Authorization: "Bearer token" },
@@ -221,6 +223,7 @@ describe("request", () => {
221223
})
222224

223225
test("should filter out ignoreSsl from fetch options", async () => {
226+
globalThis.window = undefined!
224227
await request("POST", testUrl, {
225228
body: { data: "test" },
226229
headers: { "Content-Type": "application/json" },
@@ -235,6 +238,7 @@ describe("request", () => {
235238
})
236239

237240
test("should handle mixed requests with different SSL settings", async () => {
241+
globalThis.window = undefined!
238242
// First request with SSL verification (default)
239243
await request("GET", testUrl, {
240244
headers: { Accept: "application/json" },
@@ -262,6 +266,7 @@ describe("request", () => {
262266
test("should work with all HTTP methods and ignoreSsl", async () => {
263267
const methods = ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD"]
264268
const testBody = { test: "data" }
269+
globalThis.window = undefined!
265270

266271
for (const method of methods) {
267272
vi.clearAllMocks()
@@ -293,6 +298,7 @@ describe("request", () => {
293298
})
294299

295300
test("should handle JSON body serialization with ignoreSsl", async () => {
301+
globalThis.window = undefined!
296302
const requestBody = {
297303
name: "test-resource",
298304
spec: { replicas: 3 },
@@ -315,6 +321,7 @@ describe("request", () => {
315321
})
316322

317323
test("should handle string body without modification with ignoreSsl", async () => {
324+
globalThis.window = undefined!
318325
const stringBody = "raw string data"
319326

320327
await request("POST", testUrl, {
@@ -331,6 +338,7 @@ describe("request", () => {
331338
})
332339

333340
test("should handle URL parameters with ignoreSsl", async () => {
341+
globalThis.window = undefined!
334342
await request("GET", testUrl, {
335343
params: {
336344
labelSelector: "app=nginx",

0 commit comments

Comments
 (0)