-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Testcases for all PAWS collectors #318
base: master
Are you sure you want to change the base?
Changes from all commits
8c8ed05
2786637
1358bbd
5d69890
4770616
957c049
c44b581
edeab5e
a50b6c4
2011867
c0367db
f9f996a
b74653a
7eccf99
2db7796
bb85165
d028934
ec6bb05
0676e48
078ffd9
9ed908b
fc03856
8ea7473
e14dd72
6574067
0f985df
a77f036
293c68e
d64d6aa
a198c8e
954c5e9
b0868e4
2d7fa17
c09c93b
c2027a5
e801301
9eaf5d0
b9cdde7
ab6cd63
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ process.env.paws_api_secret = "api-secret"; | |
process.env.collector_streams = "[\"AuditLogEvents\", \"SearchAlerts\",\"SearchAlertsCBAnalytics\", \"SearchAlertsWatchlist\"]"; | ||
process.env.paws_collector_param_string_2 = "carbonblackOrgKey"; | ||
process.env.paws_endpoint = "https://api-url.conferdeploy.net"; | ||
process.env.collector_streams_null = "[\"AuditLogEventsCB\", \"SearchAlertsCB\",\"SearchAlertsCBAnalyticsCB\", \"SearchAlertsWatchlistCB\"]"; | ||
|
||
|
||
const AIMS_TEST_CREDS = { | ||
access_key_id: 'test-access-key-id', | ||
|
@@ -27,7 +29,7 @@ const AIMS_TEST_CREDS = { | |
|
||
const LOG_EVENT = { | ||
"requestUrl": null, | ||
"eventTime": 1529332687006, | ||
"eventTime": "2020-05-30T13:49:11.789012Z", | ||
"eventId": "37075c01730511e89504c9ba022c3fbf", | ||
"loginName": "[email protected]", | ||
"orgName": "example.org", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,5 +115,104 @@ describe('Unit Tests', function () { | |
}); | ||
}); | ||
}); | ||
describe('Get API Logs (GET) with Error', function () { | ||
Pranav-Arya37 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
it('Get API Logs with Error (GET)', function (done) { | ||
alserviceStub.get = sinon.stub(RestServiceClient.prototype, 'get').callsFake( | ||
function fakeFn(path, extraOptions) { | ||
return new Promise(function (resolve, reject) { | ||
return reject(new Error("Failed to fetch API logs due to an authentication issue")); | ||
}); | ||
}); | ||
let maxPagesPerInvocation = 5; | ||
const startDate = moment().subtract(5, 'minutes'); | ||
let state = { | ||
stream: "AuditLogEvents", | ||
since: startDate.toISOString(), | ||
until: startDate.add(5, 'minutes').toISOString(), | ||
poll_interval_sec: 1 | ||
}; | ||
let apiDetails = { | ||
url: "url", | ||
method: "GET", | ||
requestBody:"", | ||
typeIdPaths: [{ path: ["eventId"] }], | ||
tsPaths: [{ path: ["eventTime"] }] | ||
}; | ||
let accumulator = []; | ||
const apiEndpoint = process.env.paws_endpoint; | ||
const clientSecret = process.env.paws_api_secret; | ||
const clientId = process.env.paws_api_client_id; | ||
|
||
utils.getAPILogs(apiDetails, accumulator, apiEndpoint, state, clientSecret, clientId, maxPagesPerInvocation).catch(err => { | ||
assert.equal(err.message, "Failed to fetch API logs due to an authentication issue", "Error message is not correct"); | ||
alserviceStub.get.restore(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
|
||
describe('Get API Logs (POST Request) with Error', function () { | ||
it('Get API Logs with Error (POST)', function (done) { | ||
alserviceStub.post = sinon.stub(RestServiceClient.prototype, 'post').callsFake( | ||
function fakeFn(path, extraOptions) { | ||
return new Promise(function (resolve, reject) { | ||
return reject(new Error("Failed to fetch API logs due to an authentication issue")); | ||
}); | ||
}); | ||
let maxPagesPerInvocation = 5; | ||
const startDate = moment().subtract(5, 'minutes'); | ||
let state = { | ||
stream: "SearchAlerts", | ||
since: startDate.toISOString(), | ||
until: startDate.add(5, 'minutes').toISOString(), | ||
poll_interval_sec: 1 | ||
}; | ||
let apiDetails = { | ||
url: "url", | ||
method: "POST", | ||
requestBody:{ | ||
"criteria": { | ||
"create_time": { | ||
"end": state.until, | ||
"start": state.since | ||
}, | ||
}, | ||
"rows": 0, | ||
"start": 0 | ||
}, | ||
typeIdPaths: [{ path: ["id"] }], | ||
tsPaths: [{ path: ["last_update_time"] }] | ||
}; | ||
let accumulator = []; | ||
const apiEndpoint = process.env.paws_endpoint; | ||
const clientSecret = process.env.paws_api_secret; | ||
const clientId = process.env.paws_api_client_id; | ||
|
||
utils.getAPILogs(apiDetails, accumulator, apiEndpoint, state, clientSecret, clientId, maxPagesPerInvocation).catch(err => { | ||
assert.equal(err.message, "Failed to fetch API logs due to an authentication issue", "Error message is not correct"); | ||
alserviceStub.post.restore(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Get API Details when state.stream is null', function () { | ||
it('Get API Details when state.stream is null', function (done) { | ||
const startDate = moment().subtract(5, 'minutes'); | ||
const orgKey = "orgKey"; | ||
let apiDetails = []; | ||
const apiNames = JSON.parse(process.env.collector_streams_null); | ||
apiNames.map(stream => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. process.env.collector_streams_null pls rename to proper name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pls check the above comment and resolve There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have added the reason, why I have added this code, in this comment. (#318 (comment)) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rename the variable name collector_streams_null |
||
let state = { | ||
stream: null, | ||
since: startDate.toISOString(), | ||
until: startDate.add(5, 'minutes').toISOString(), | ||
poll_interval_sec: 1 | ||
}; | ||
apiDetails.push(utils.getAPIDetails(state, orgKey)); | ||
}); | ||
assert(apiDetails.length == apiNames.length, "apiDetails length is wrong"); | ||
done(); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
collector_streams_null what is the purpose of adding this env variable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added this, to include this default functionality in the test-case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename the variable name collector_streams_null