mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-10-19 01:44:16 +00:00
- Replace `any` with `unknown` + type guards in finding-groups and findings-by-resource adapters (4 adapter functions hardened) - Add unmount cleanup for AbortController in use-resource-detail-drawer to prevent memory leaks on mid-flight unmount - Add try/catch/finally error handling for onBeforeOpen in floating mute button to prevent permanent spinner state on network errors - Replace hardcoded colors (border-gray-300, bg-white, text-slate-950) with semantic tokens (border-default-200, bg-background, text-foreground) for dark mode compatibility - Change non-accessible `<p onClick>` to `<button>` with w-full and type=button in column-finding-groups for keyboard accessibility - Fix region flag mapping: asia-east1 (Taiwan) now correctly shows flag_tw instead of flag_hk by adding specific rule before Hong Kong regex - Fix import type usage in adapter files (value imports preserved for runtime constants like FINDINGS_ROW_TYPE) - Restore pageRef.current = 1 in refresh() for error path safety 43 new tests across 7 test files. 50 total tests passing. TypeScript: 0 errors. ESLint: 0 errors. Judgment Day: 2 rounds, 0 discrepancies remaining.
183 lines
4.7 KiB
TypeScript
183 lines
4.7 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
adaptFindingGroupResourcesResponse,
|
|
adaptFindingGroupsResponse,
|
|
} from "./finding-groups.adapter";
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Fix 1: adaptFindingGroupsResponse — unknown + type guard
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe("adaptFindingGroupsResponse — malformed input", () => {
|
|
it("should return [] when apiResponse is null", () => {
|
|
// Given
|
|
const input = null;
|
|
|
|
// When
|
|
const result = adaptFindingGroupsResponse(input);
|
|
|
|
// Then
|
|
expect(result).toEqual([]);
|
|
});
|
|
|
|
it("should return [] when apiResponse has no data property", () => {
|
|
// Given
|
|
const input = { meta: { total: 0 } };
|
|
|
|
// When
|
|
const result = adaptFindingGroupsResponse(input);
|
|
|
|
// Then
|
|
expect(result).toEqual([]);
|
|
});
|
|
|
|
it("should return [] when data is not an array", () => {
|
|
// Given
|
|
const input = { data: "not-an-array" };
|
|
|
|
// When
|
|
const result = adaptFindingGroupsResponse(input);
|
|
|
|
// Then
|
|
expect(result).toEqual([]);
|
|
});
|
|
|
|
it("should return [] when data is null", () => {
|
|
// Given
|
|
const input = { data: null };
|
|
|
|
// When
|
|
const result = adaptFindingGroupsResponse(input);
|
|
|
|
// Then
|
|
expect(result).toEqual([]);
|
|
});
|
|
|
|
it("should return [] when apiResponse is undefined", () => {
|
|
// Given
|
|
const input = undefined;
|
|
|
|
// When
|
|
const result = adaptFindingGroupsResponse(input);
|
|
|
|
// Then
|
|
expect(result).toEqual([]);
|
|
});
|
|
|
|
it("should return mapped rows for valid data", () => {
|
|
// Given
|
|
const input = {
|
|
data: [
|
|
{
|
|
id: "group-1",
|
|
type: "finding-groups",
|
|
attributes: {
|
|
check_id: "s3_bucket_public_access",
|
|
check_title: "S3 Bucket Public Access",
|
|
check_description: null,
|
|
severity: "critical",
|
|
status: "FAIL",
|
|
impacted_providers: ["aws"],
|
|
resources_total: 5,
|
|
resources_fail: 3,
|
|
pass_count: 2,
|
|
fail_count: 3,
|
|
muted_count: 0,
|
|
new_count: 1,
|
|
changed_count: 0,
|
|
first_seen_at: null,
|
|
last_seen_at: "2024-01-01T00:00:00Z",
|
|
failing_since: null,
|
|
},
|
|
},
|
|
],
|
|
};
|
|
|
|
// When
|
|
const result = adaptFindingGroupsResponse(input);
|
|
|
|
// Then
|
|
expect(result).toHaveLength(1);
|
|
expect(result[0].checkId).toBe("s3_bucket_public_access");
|
|
expect(result[0].checkTitle).toBe("S3 Bucket Public Access");
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Fix 1: adaptFindingGroupResourcesResponse — unknown + type guard
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe("adaptFindingGroupResourcesResponse — malformed input", () => {
|
|
it("should return [] when apiResponse is null", () => {
|
|
// Given/When
|
|
const result = adaptFindingGroupResourcesResponse(null, "check-1");
|
|
|
|
// Then
|
|
expect(result).toEqual([]);
|
|
});
|
|
|
|
it("should return [] when apiResponse has no data property", () => {
|
|
// Given/When
|
|
const result = adaptFindingGroupResourcesResponse({ meta: {} }, "check-1");
|
|
|
|
// Then
|
|
expect(result).toEqual([]);
|
|
});
|
|
|
|
it("should return [] when data is not an array", () => {
|
|
// Given/When
|
|
const result = adaptFindingGroupResourcesResponse({ data: {} }, "check-1");
|
|
|
|
// Then
|
|
expect(result).toEqual([]);
|
|
});
|
|
|
|
it("should return [] when apiResponse is undefined", () => {
|
|
// Given/When
|
|
const result = adaptFindingGroupResourcesResponse(undefined, "check-1");
|
|
|
|
// Then
|
|
expect(result).toEqual([]);
|
|
});
|
|
|
|
it("should return mapped rows for valid data", () => {
|
|
// Given
|
|
const input = {
|
|
data: [
|
|
{
|
|
id: "resource-row-1",
|
|
type: "finding-group-resources",
|
|
attributes: {
|
|
resource: {
|
|
uid: "arn:aws:s3:::my-bucket",
|
|
name: "my-bucket",
|
|
service: "s3",
|
|
region: "us-east-1",
|
|
type: "Bucket",
|
|
resource_group: "default",
|
|
},
|
|
provider: {
|
|
type: "aws",
|
|
uid: "123456789",
|
|
alias: "production",
|
|
},
|
|
status: "FAIL",
|
|
severity: "critical",
|
|
first_seen_at: null,
|
|
last_seen_at: "2024-01-01T00:00:00Z",
|
|
},
|
|
},
|
|
],
|
|
};
|
|
|
|
// When
|
|
const result = adaptFindingGroupResourcesResponse(input, "s3_check");
|
|
|
|
// Then
|
|
expect(result).toHaveLength(1);
|
|
expect(result[0].checkId).toBe("s3_check");
|
|
expect(result[0].resourceName).toBe("my-bucket");
|
|
});
|
|
});
|