Skip to content

Commit aabb705

Browse files
committed
refactor(worker): improve AbuseIPDB component quality
- Renamed files from abusedb to abuseipdb for clarity - Extracted port definitions to avoid duplication between metadata and resolvePorts - Added parameters array for maxAgeInDays and verbose in metadata - Improved type safety by removing 'as any' assertions - Added AbuseIPDBOutput interface in tests - Added test cases for validation errors and verbose parameter - Fixed readonly array type mismatch with SDK Signed-off-by: betterclever <[email protected]>
1 parent 6c745c0 commit aabb705

File tree

6 files changed

+345
-218
lines changed

6 files changed

+345
-218
lines changed

worker/src/components/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ import './security/atlassian-offboarding';
5555
import './security/trufflehog';
5656
import './security/terminal-demo';
5757
import './security/virustotal';
58-
import './security/abusedb';
58+
import './security/abuseipdb';
5959

6060
// GitHub components
6161
import './github/connection-provider';

worker/src/components/security/__tests__/abusedb-integration.test.ts

Lines changed: 0 additions & 46 deletions
This file was deleted.

worker/src/components/security/__tests__/abusedb.test.ts

Lines changed: 0 additions & 125 deletions
This file was deleted.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/**
2+
* Optional integration test for AbuseIPDB component.
3+
* Requires a valid AbuseIPDB API key.
4+
* Enable by setting RUN_ABUSEDB_TESTS=1 and providing ABUSEIPDB_API_KEY.
5+
*/
6+
import { describe, expect, test, beforeEach } from 'bun:test';
7+
import { componentRegistry, createExecutionContext, type ExecutionContext } from '@shipsec/component-sdk';
8+
import '../../index'; // Ensure registry is populated
9+
10+
interface AbuseIPDBOutput {
11+
ipAddress: string;
12+
isPublic?: boolean;
13+
ipVersion?: number;
14+
isWhitelisted?: boolean;
15+
abuseConfidenceScore: number;
16+
countryCode?: string;
17+
usageType?: string;
18+
isp?: string;
19+
domain?: string;
20+
hostnames?: string[];
21+
totalReports?: number;
22+
numDistinctUsers?: number;
23+
lastReportedAt?: string;
24+
reports?: Record<string, unknown>[];
25+
full_report: Record<string, unknown>;
26+
}
27+
28+
const shouldRunIntegration =
29+
process.env.RUN_ABUSEDB_TESTS === '1' && !!process.env.ABUSEIPDB_API_KEY;
30+
31+
(shouldRunIntegration ? describe : describe.skip)('AbuseIPDB Integration', () => {
32+
let context: ExecutionContext;
33+
34+
beforeEach(async () => {
35+
context = createExecutionContext({
36+
runId: 'test-run',
37+
componentRef: 'abuseipdb-integration-test',
38+
});
39+
});
40+
41+
test('checks a known IP address', async () => {
42+
const component = componentRegistry.get('security.abuseipdb.check');
43+
expect(component).toBeDefined();
44+
45+
// 1.1.1.1 is Cloudflare DNS and should exist in AbuseIPDB
46+
const ipToCheck = '1.1.1.1';
47+
48+
const params = {
49+
ipAddress: ipToCheck,
50+
apiKey: process.env.ABUSEIPDB_API_KEY!,
51+
maxAgeInDays: 90,
52+
verbose: true
53+
};
54+
55+
const result = await component!.execute(params, context) as AbuseIPDBOutput;
56+
57+
expect(result.ipAddress).toBe(ipToCheck);
58+
expect(typeof result.abuseConfidenceScore).toBe('number');
59+
expect(result.full_report).toBeDefined();
60+
});
61+
62+
test('checks a known malicious IP address', async () => {
63+
const component = componentRegistry.get('security.abuseipdb.check');
64+
expect(component).toBeDefined();
65+
66+
// Using Google DNS as a safe, known IP
67+
const ipToCheck = '8.8.8.8';
68+
69+
const params = {
70+
ipAddress: ipToCheck,
71+
apiKey: process.env.ABUSEIPDB_API_KEY!,
72+
maxAgeInDays: 90,
73+
verbose: false
74+
};
75+
76+
const result = await component!.execute(params, context) as AbuseIPDBOutput;
77+
78+
expect(result.ipAddress).toBe(ipToCheck);
79+
expect(typeof result.abuseConfidenceScore).toBe('number');
80+
expect(result.abuseConfidenceScore).toBeGreaterThanOrEqual(0);
81+
expect(result.abuseConfidenceScore).toBeLessThanOrEqual(100);
82+
});
83+
});

0 commit comments

Comments
 (0)