forked from arkime/arkime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api-users.t
71 lines (53 loc) · 4.64 KB
/
api-users.t
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
use Test::More tests => 19;
use Cwd;
use URI::Escape;
use MolochTest;
use JSON;
use Test::Differences;
use strict;
my $pwd = getcwd() . "/pcap";
my $token = getToken();
my $token2 = getToken2();
# users
my $users = viewerPost("/users.json", "");
is (@{$users->{aaData}}, 0, "Empty users table");
# Add User 1
my $json = viewerPost("/addUser", "token=$token&userId=test1&userName=UserName&enabled=on&password=password");
$users = viewerPost("/users.json", "");
is (@{$users->{aaData}}, 1, "Check add #1");
eq_or_diff($users->{aaData}->[0], from_json('{"createEnabled": false, "userId": "test1", "removeEnabled": false, "expression": "", "headerAuthEnabled": false, "userName": "UserName", "id": "test1", "emailSearch": false, "enabled": true, "webEnabled": false}', {relaxed => 1}), "Test User Add", { context => 3 });
$users = viewerPost2("/users.json", "");
is (@{$users->{aaData}}, 1, "Check add #2");
eq_or_diff($users->{aaData}->[0], from_json('{"createEnabled": false, "userId": "test1", "removeEnabled": false, "expression": "", "headerAuthEnabled": false, "userName": "UserName", "id": "test1", "emailSearch": false, "enabled": true, "webEnabled": false}', {relaxed => 1}), "Test User Add", { context => 3 });
# Update User Server 1
$json = viewerPost("/updateUser/test1?userName=UserNameUpdated&removeEnabled=true&headerAuthEnabled=true&expression=foo&emailSearch=true&webEnabled=true&createEnabled=true", "token=$token");
$users = viewerPost("/users.json", "");
is (@{$users->{aaData}}, 1, "Check Update #1");
eq_or_diff($users->{aaData}->[0], from_json('{"createEnabled": true, "userId": "test1", "removeEnabled": true, "expression": "foo", "headerAuthEnabled": true, "userName": "UserNameUpdated", "id": "test1", "emailSearch": true, "enabled": true, "webEnabled": true}', {relaxed => 1}), "Test User Update", { context => 3 });
$users = viewerPost2("/users.json", "");
is (@{$users->{aaData}}, 1, "Check Update #2");
eq_or_diff($users->{aaData}->[0], from_json('{"createEnabled": true, "userId": "test1", "removeEnabled": true, "expression": "foo", "headerAuthEnabled": true, "userName": "UserNameUpdated", "id": "test1", "emailSearch": true, "enabled": true, "webEnabled": true}', {relaxed => 1}), "Test User Update", { context => 3 });
# Add User 2
my $json = viewerPost2("/addUser", "token=$token2&userId=test2&userName=UserName2&enabled=on&password=password");
$users = viewerPost("/users.json", "");
is (@{$users->{aaData}}, 2, "Check second add #1");
eq_or_diff($users->{aaData}->[1], from_json('{"createEnabled": false, "userId": "test2", "removeEnabled": false, "expression": "", "headerAuthEnabled": false, "userName": "UserName2", "id": "test2", "emailSearch": false, "enabled": true, "webEnabled": false}', {relaxed => 1}), "Test User Add", { context => 3 });
$users = viewerPost2("/users.json", "");
is (@{$users->{aaData}}, 2, "Check second add #2");
eq_or_diff($users->{aaData}->[1], from_json('{"createEnabled": false, "userId": "test2", "removeEnabled": false, "expression": "", "headerAuthEnabled": false, "userName": "UserName2", "id": "test2", "emailSearch": false, "enabled": true, "webEnabled": false}', {relaxed => 1}), "Test User Add", { context => 3 });
# Update User Shared Server
$json = viewerPost2("/updateUser/test2?userName=UserNameUpdated2&removeEnabled=false&headerAuthEnabled=true&expression=foo&emailSearch=true&webEnabled=true&createEnabled=true", "token=$token2");
$users = viewerPost("/users.json", "");
is (@{$users->{aaData}}, 2, "Check second Update #1");
eq_or_diff($users->{aaData}->[1], from_json('{"createEnabled": true, "userId": "test2", "removeEnabled": false, "expression": "foo", "headerAuthEnabled": true, "userName": "UserNameUpdated2", "id": "test2", "emailSearch": true, "enabled": true, "webEnabled": true}', {relaxed => 1}), "Test User Update", { context => 3 });
$users = viewerPost2("/users.json", "");
is (@{$users->{aaData}}, 2, "Check second Update #2");
eq_or_diff($users->{aaData}->[1], from_json('{"createEnabled": true, "userId": "test2", "removeEnabled": false, "expression": "foo", "headerAuthEnabled": true, "userName": "UserNameUpdated2", "id": "test2", "emailSearch": true, "enabled": true, "webEnabled": true}', {relaxed => 1}), "Test User Update", { context => 3 });
# Delete Users
$json = viewerPost("/deleteUser/test1", "token=$token");
$json = viewerPost2("/deleteUser/test2", "token=$token2");
esGet("/_refresh");
$users = viewerPost("/users.json", "");
is (@{$users->{aaData}}, 0, "Removed user #1");
$users = viewerPost2("/users.json", "");
is (@{$users->{aaData}}, 0, "Removed user #2");