Skip to content
This repository has been archived by the owner on Oct 20, 2023. It is now read-only.

Commit

Permalink
Small Test Updates (#178)
Browse files Browse the repository at this point in the history
* Use a built version of the client for cypress tests to improve performance
Change beacon count for raw logs test because we've removed the server beacon from the count
Change beacon name for hide-beacon tests because they have been updated to display different information
Catch command type endpoint error and return empty array

* Fix hide-beacon text select
Fix lint warning with Cypress global in d.ts file

* Add test-app command
  • Loading branch information
GoldingAustin authored Aug 30, 2023
1 parent 1ea4865 commit fc3ae6d
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 58 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ jobs:
uses: cypress-io/github-action@v5
with:
tag: node-${{ matrix.node }}
start: yarn start:dev
start: yarn start:test-app
wait-on: 'http://localhost:4000/api/graphql, http://localhost:3500'
browser: chrome
group: 'Red Team - Chrome'
Expand Down Expand Up @@ -140,7 +140,7 @@ jobs:
uses: cypress-io/github-action@v5
with:
tag: node-${{ matrix.node }}
start: yarn start:blue
start: yarn start:test-app
wait-on: 'http://localhost:4000/api/graphql, http://localhost:3500'
browser: chrome
group: 'Blue Team - Chrome'
Expand All @@ -152,6 +152,7 @@ jobs:
ci-build-id: ${{ needs.prepare.outputs.uuid }}
env:
CYPRESS_PROJECT_ID: '46ahz3'
SERVER_BLUE_TEAM: 'true'
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY_BLUE }}

# RedTeamFirefox:
Expand Down
12 changes: 12 additions & 0 deletions .moon/tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,18 @@ tasks:
options:
runInCI: false
runDepsInParallel: false
preview-vite:
command: 'vite preview --port 3500'
inputs:
- '@globs(sources)'
- '@globs(assets)'
- 'vite.config.ts'
local: true
platform: node
deps:
- ~:build-vite
options:
runInCI: false

# Library mode commands
build-library:
Expand Down
5 changes: 5 additions & 0 deletions applications/client/src/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ declare module '*?worker' {
// eslint-disable-next-line import/no-default-export
export default workerConstructor;
}

declare global {
// eslint-disable-next-line no-var,vars-on-top
var Cypress: any | undefined;
}
2 changes: 1 addition & 1 deletion applications/client/src/store/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class Auth extends ExtendedModel(RedEyeModel, {
promptAuth: prop<boolean>(false).withSetter(),
hasClickedAuthDialog: prop<boolean>(false).withSetter(),
user: prop<string>(() => localStorage.getItem('user') ?? ''),
serverUrl: prop<string>(() => (import.meta.env.DEV ? defaultServerUrl : '')),
serverUrl: prop<string>(() => (import.meta.env.DEV || globalThis.Cypress ? defaultServerUrl : '')),
}) {
get userName(): string | null {
return localStorage.getItem('user');
Expand Down
2 changes: 1 addition & 1 deletion applications/redeye-e2e/moon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ tasks:
open-cy:
command: 'noop'
deps:
- 'client:start-dev'
- 'client:preview-vite'
- 'server:start-dev'
- 'redeye-e2e:start'
local: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,12 @@ describe('Hide a Beacon using GraphQL', () => {
cy.clickBeaconsTab();
const beacs = [];
cy.get('[cy-test=beacons-row]')
.each(($li) => beacs.push($li.text()))
.each(($li) =>
beacs.push(`${$li.find('[cy-test=beacon-time]').text()}${$li.find('[cy-test=beacon-display-name]').text()}`)
)
.then(() => {
cy.log(beacs.join(', '));
cy.wrap(beacs).should('deep.equal', [
'08/17—08/17500978634 · SYSTEM *SYSTEM *8',
'08/17—08/171042756528 · user01user0114',
]);
cy.wrap(beacs).should('deep.equal', ['08/17—08/17500978634 · SYSTEM *', '08/17—08/171042756528 · user01']);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,16 @@ describe('Hide a Beacon using GraphQL', () => {
cy.clickBeaconsTab();
const beacs = [];
cy.get('[cy-test=beacons-row]')
.each(($li) => beacs.push($li.text()))
.each(($li) =>
beacs.push(`${$li.find('[cy-test=beacon-time]').text()}${$li.find('[cy-test=beacon-display-name]').text()}`)
)
.then(() => {
// cy.log(beacs.join(', '));
cy.wrap(beacs).should('deep.equal', [
'08/17—08/17330588776 · jdoejdoe9',
'08/17—08/172146137244 · jdoe *jdoe *9',
'08/17—08/17500978634 · SYSTEM *SYSTEM *8',
'08/17—08/171042756528 · user01user0114',
'08/17—08/17330588776 · jdoe',
'08/17—08/172146137244 · jdoe *',
'08/17—08/17500978634 · SYSTEM *',
'08/17—08/171042756528 · user01',
]);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('Upload raw log', () => {

cy.reload();

cy.get('[cy-test=beacon-count]').invoke('text').should('contain', '4');
cy.get('[cy-test=beacon-count]', { timeout: 25000 }).invoke('text').should('contain', '3');

cy.get('[cy-test=command-count]').invoke('text').should('contain', '7');
});
Expand Down
91 changes: 48 additions & 43 deletions applications/server/src/store/command-resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,35 +211,17 @@ export class CommandTypeCountResolvers {
@Arg('hidden', () => Boolean, { defaultValue: false, nullable: true, description: 'Should show hidden values' })
hidden: boolean = false
): Promise<CommandTypeCount[]> {
const em = await connectToProjectEmOrFail(campaignId, ctx);
const commands = await em.find(Command, beaconHidden(hidden), {
populate: ['commandGroups', 'commandGroups.annotations'],
});
const countObj = commands.reduce<Record<string, CountObjItem>>((acc, current) => {
if (acc[current.inputText]) {
acc[current.inputText] = {
count: acc[current.inputText].count + 1,
beaconIds: [...acc[current.inputText].beaconIds, current.beacon.id],
commentsCount: current.commandGroups?.getItems().reduce((commentsCountItem, group) => {
if (!commentsCountItem.commandGroupIds.includes(group.id)) {
return {
commandGroupIds: [...commentsCountItem.commandGroupIds, group.id],
count: commentsCountItem.count + (group?.annotations?.count() ?? 0),
};
} else {
return {
commandGroupIds: [...commentsCountItem.commandGroupIds, group.id],
count: commentsCountItem.count,
};
}
}, acc[current.inputText].commentsCount),
};
} else {
acc[current.inputText] = {
count: 1,
beaconIds: [current.beacon.id],
commentsCount: current.commandGroups?.getItems().reduce(
(commentsCountItem, group) => {
try {
const em = await connectToProjectEmOrFail(campaignId, ctx);
const commands = await em.find(Command, beaconHidden(hidden), {
populate: ['commandGroups', 'commandGroups.annotations'],
});
const countObj = commands.reduce<Record<string, CountObjItem>>((acc, current) => {
if (acc[current.inputText]) {
acc[current.inputText] = {
count: acc[current.inputText].count + 1,
beaconIds: [...acc[current.inputText].beaconIds, current.beacon.id],
commentsCount: current.commandGroups?.getItems().reduce((commentsCountItem, group) => {
if (!commentsCountItem.commandGroupIds.includes(group.id)) {
return {
commandGroupIds: [...commentsCountItem.commandGroupIds, group.id],
Expand All @@ -251,21 +233,44 @@ export class CommandTypeCountResolvers {
count: commentsCountItem.count,
};
}
},
{ commandGroupIds: [], count: 0 } as CommentsCountItem
),
};
}
return acc;
}, {});
}, acc[current.inputText].commentsCount),
};
} else {
acc[current.inputText] = {
count: 1,
beaconIds: [current.beacon.id],
commentsCount: current.commandGroups?.getItems().reduce(
(commentsCountItem, group) => {
if (!commentsCountItem.commandGroupIds.includes(group.id)) {
return {
commandGroupIds: [...commentsCountItem.commandGroupIds, group.id],
count: commentsCountItem.count + (group?.annotations?.count() ?? 0),
};
} else {
return {
commandGroupIds: [...commentsCountItem.commandGroupIds, group.id],
count: commentsCountItem.count,
};
}
},
{ commandGroupIds: [], count: 0 } as CommentsCountItem
),
};
}
return acc;
}, {});

return Object.entries(countObj).map(([text, item]) => ({
id: text,
text,
count: item.count,
beaconsCount: new Set(item.beaconIds).size,
commentsCount: item.commentsCount.count,
})) as CommandTypeCount[];
return Object.entries(countObj || {}).map(([text, item]) => ({
id: text,
text,
count: item.count,
beaconsCount: new Set(item.beaconIds).size,
commentsCount: item.commentsCount.count,
})) as CommandTypeCount[];
} catch (e) {
console.error(e);
return [];
}
}
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"start:client": "yarn moon run @redeye/client:start-dev",
"start:server": "yarn moon run @redeye/server:start-dev",
"start:dev": "yarn moon run @redeye/server:start-dev @redeye/client:start-dev",
"start:test-app": "yarn moon run @redeye/server:start-dev @redeye/client:preview-vite",
"start:graph": "yarn moon run @redeye/graph:start-vite",
"start:landing": "yarn moon run @redeye/landing:start-astro",
"combine:reports": "jrm dist/applications/redeye-e2e/results/combined-report.xml \"dist/applications/redeye-e2e/results/*.xml\"",
Expand Down

0 comments on commit fc3ae6d

Please sign in to comment.