-
Notifications
You must be signed in to change notification settings - Fork 0
/
shodan_test.ts
104 lines (95 loc) · 2.83 KB
/
shodan_test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { stub, Stub, assertEquals } from "./dev_deps.ts";
import { Shodan } from "./shodan.ts";
Deno.test("host() assert", async () => {
const shodan = new Shodan("somekey");
const mockResponse = {
ip: 11111,
country_code: "SG",
org: "Microsoft Azure",
data: [{
ip: 11111,
port: 22,
transport: "tcp",
version: "7.6p1 Ubuntu-4ubuntu0.3",
product: "OpenSSH",
timestamp: "2020-05-08T19:33:51.534128",
org: "Microsoft Azure",
info: "protocol 2.0",
isp: "Microsoft Corporation",
ip_str: "127.0.0.1",
}],
city: "Singapore",
isp: "Microsoft Corporation",
last_update: "2020-05-08T19:33:51.534128",
country_name: "Singapore",
ip_str: "127.0.0.1",
ports: [22],
};
const host: Stub<Shodan> = stub(shodan, "host", () => mockResponse);
assertEquals(await shodan.host("127.0.01"), mockResponse);
});
Deno.test("search() assert", async () => {
const shodan = new Shodan("somekey");
const mockResponse = {
matches: [{
tags: ["cloud"],
ip: 111111,
isp: "Amazon.com",
http: {
title: "Some website title",
securitytxt: null,
robots: "User-agent: *\nDisallow:\n",
location: "/",
server: "nginx",
},
port: 80,
hostnames: ["somehostname.compute.amazonaws.com"],
location: {
city: "London",
region_code: "ENG",
country_name: "United Kingdom",
country_code: "GB",
},
timestamp: "2020-05-10T10:03:01.419191",
domains: ["amazonaws.com"],
org: "Amazon.com",
transport: "tcp",
ip_str: "127.0.0.1",
}],
total: 1,
};
const search: Stub<Shodan> = stub(shodan, "search", () => mockResponse);
assertEquals(await shodan.search("laravel port:80"), mockResponse);
});
Deno.test("profile() assert", async () => {
const shodan = new Shodan("somekey");
const mockResponse = {
"member": true,
"credits": 42,
"display_name": "Woyo",
"created": "2014-04-15T07:34:40",
};
const profile: Stub<Shodan> = stub(shodan, "profile", () => mockResponse);
assertEquals(await shodan.profile(), mockResponse);
});
Deno.test("myIP() assert", async () => {
const shodan = new Shodan("somekey");
const myIP: Stub<Shodan> = stub(shodan, "myIP", () => `"74.125.227.230"`);
assertEquals(await shodan.myIP(), `"74.125.227.230"`);
});
Deno.test("apiInfo() assert", async () => {
const shodan = new Shodan("somekey");
const mockResponse = {
scan_credits: 100,
usage_limits: { scan_credits: 100, query_credits: 100, monitored_ips: 16 },
plan: "dev",
https: false,
unlocked: true,
query_credits: 100,
monitored_ips: 0,
unlocked_left: 100,
telnet: false,
};
const profile: Stub<Shodan> = stub(shodan, "apiInfo", () => mockResponse);
assertEquals(await shodan.apiInfo(), mockResponse);
});