Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { AlertService } from '@services/shared/alert.service';

import { HashlistPretaskBuilderDataSource } from '@datasources/hashlist-pretask-builder.datasource';

import { StaticChunkingMode } from '@src/app/core/_constants/tasks.config';
import { environment } from '@src/environments/environment';

@Component({
Expand Down Expand Up @@ -186,7 +187,7 @@ export class HashlistPretaskBuilderTableComponent implements OnInit, OnDestroy {
crackerBinaryId,
isArchived: false,
notes: '',
staticChunks: 0,
staticChunks: StaticChunkingMode.NONE,
chunkSize: Number(environment.config.tasks.chunkSize),
forcePipe: false,
preprocessorId: 0,
Expand Down
17 changes: 13 additions & 4 deletions src/app/core/_constants/tasks.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
export const staticChunking = [
{ id: 0, name: 'No' },
{ id: 1, name: 'Fixed chunk size' },
{ id: 2, name: 'Fixed number of chunks' }
import { SelectOption } from '@src/app/shared/utils/forms';

export const StaticChunkingMode = {
NONE: 0,
FIXED_CHUNK_SIZE: 1,
FIXED_NUMBER_OF_CHUNKS: 2
} as const;
export type StaticChunkingMode = (typeof StaticChunkingMode)[keyof typeof StaticChunkingMode];

export const staticChunking: SelectOption<number>[] = [
{ id: StaticChunkingMode.NONE, name: 'No' },
{ id: StaticChunkingMode.FIXED_CHUNK_SIZE, name: 'Fixed chunk size' },
{ id: StaticChunkingMode.FIXED_NUMBER_OF_CHUNKS, name: 'Fixed number of chunks' }
];

export const benchmarkType = [
Expand Down
2 changes: 1 addition & 1 deletion src/app/tasks/edit-tasks/edit-tasks.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<input-number title="Priority" formControlName="priority"></input-number>
<input-number title="Status timer" formControlName="statusTimer"></input-number>
<input-number title="Max agents" formControlName="maxAgents"></input-number>
<input-number title="Chunk size" formControlName="chunkTime"></input-number>
<input-number title="Chunk time" formControlName="chunkTime"></input-number>
</app-form-row>
<app-form-row align="left">
<input-check title="CPU only" formControlName="isCpuTask"></input-check>
Expand Down
44 changes: 27 additions & 17 deletions src/app/tasks/edit-tasks/edit-tasks.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { AlertService } from '@services/shared/alert.service';
import { AutoTitleService } from '@services/shared/autotitle.service';
import { ConfigService } from '@services/shared/config.service';

import { StaticChunkingMode } from '@src/app/core/_constants/tasks.config';
import { EditTasksComponent } from '@src/app/tasks/edit-tasks/edit-tasks.component';
import { mockResponse } from '@src/app/testing/mock-response';

Expand Down Expand Up @@ -271,13 +272,13 @@ describe('EditTasksComponent', () => {
expect(component.updateForm.getRawValue()['skipKeyspace']).toBe(500);
}));

it('should label staticChunks=1 as "Fixed chunk size (1)"', fakeAsync(() => {
function loadWithStaticChunks(staticChunks: number): string {
const response = mockResponse({
data: {
...(mockTaskResponse().data as object),
attributes: {
...((mockTaskResponse().data as Record<string, unknown>)['attributes'] as object),
staticChunks: 1
staticChunks
}
}
}) as ResponseWrapper;
Expand All @@ -286,25 +287,34 @@ describe('EditTasksComponent', () => {
respondToTaskRequest(response);
tick();

expect(component.updateForm.getRawValue()['staticChunks']).toBe('Fixed chunk size (1)');
return component.updateForm.getRawValue()['staticChunks'];
}

it('should label staticChunks=0 as "No"', fakeAsync(() => {
expect(loadWithStaticChunks(StaticChunkingMode.NONE)).toBe('No');
}));

it('should label staticChunks=2 as "Fixed number of chunks (2)"', fakeAsync(() => {
const response = mockResponse({
data: {
...(mockTaskResponse().data as object),
attributes: {
...((mockTaskResponse().data as Record<string, unknown>)['attributes'] as object),
staticChunks: 2
}
}
}) as ResponseWrapper;
it('should label staticChunks=1 with the fixed chunk size', fakeAsync(() => {
expect(loadWithStaticChunks(StaticChunkingMode.FIXED_CHUNK_SIZE)).toBe(
`Fixed chunksize: ${(1000).toLocaleString()}`
);
}));

initComponent();
respondToTaskRequest(response);
tick();
it('should label staticChunks=2 with the fixed number of chunks', fakeAsync(() => {
expect(loadWithStaticChunks(StaticChunkingMode.FIXED_NUMBER_OF_CHUNKS)).toBe(
`Fixed number of chunks: ${(1000).toLocaleString()}`
);
}));

it('should render the static chunking field in the task information form', fakeAsync(() => {
loadWithStaticChunks(StaticChunkingMode.FIXED_CHUNK_SIZE);
fixture.detectChanges();

const field: HTMLElement | null = fixture.nativeElement.querySelector(
'input-text[formControlName="staticChunks"]'
);

expect(component.updateForm.getRawValue()['staticChunks']).toBe('Fixed number of chunks (2)');
expect(field?.getAttribute('title')).toBe('Use static chunking');
}));

it('should navigate to /not-found on 404 error', fakeAsync(() => {
Expand Down
13 changes: 7 additions & 6 deletions src/app/tasks/edit-tasks/edit-tasks.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { TasksAgentsTableComponent } from '@components/tables/tasks-agents-table
import { TasksChunksTableComponent } from '@components/tables/tasks-chunks-table/tasks-chunks-table.component';

import { AGENT_MAPPING } from '@src/app/core/_constants/select.config';
import { StaticChunkingMode } from '@src/app/core/_constants/tasks.config';
import { FileSizePipe } from '@src/app/core/_pipes/file-size.pipe';
import { attackCommandWithAliasValidator } from '@src/app/core/_validators/attack-command.validator';
import { SelectOption, transformSelectOptions } from '@src/app/shared/utils/forms';
Expand Down Expand Up @@ -162,7 +163,7 @@ export class EditTasksComponent implements OnInit, OnDestroy {
this.updateForm.setValue({
taskId: task.id,
forcePipe: task.forcePipe === true ? 'Yes' : 'No',
staticChunks: this.getStaticChunkingLabel(task.staticChunks),
staticChunks: this.getStaticChunkingLabel(task.staticChunks, task.chunkSize),
skipKeyspace: task.skipKeyspace > 0 ? task.skipKeyspace : 'N/A',
keyspace: task.keyspace,
keyspaceProgress: task.keyspaceProgress,
Expand Down Expand Up @@ -498,12 +499,12 @@ export class EditTasksComponent implements OnInit, OnDestroy {
});
}

private getStaticChunkingLabel(staticChunks: number): string {
private getStaticChunkingLabel(staticChunks: number, chunkSize: number): string {
switch (staticChunks) {
case 1:
return 'Fixed chunk size (1)';
case 2:
return 'Fixed number of chunks (2)';
case StaticChunkingMode.FIXED_CHUNK_SIZE:
return `Fixed chunksize: ${chunkSize.toLocaleString()}`;
case StaticChunkingMode.FIXED_NUMBER_OF_CHUNKS:
return `Fixed number of chunks: ${chunkSize.toLocaleString()}`;
default:
return 'No';
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/tasks/new-tasks/new-tasks.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ <h2 class="text-sm font-medium text-muted-foreground uppercase tracking-wide">Ta
formControlName="staticChunks"
[items]="selectStaticChunking"
></input-select>
@if (form.controls.staticChunks.value === 1) {
@if (form.controls.staticChunks.value === StaticChunkingMode.FIXED_CHUNK_SIZE) {
<input-number
title="Fixed size of chunks"
formControlName="chunkSize"
[tooltip]="tasktip.chunkSize"
></input-number>
} @else if (form.controls.staticChunks.value === 2) {
} @else if (form.controls.staticChunks.value === StaticChunkingMode.FIXED_NUMBER_OF_CHUNKS) {
<input-number title="Fixed number of chunks" formControlName="chunkSize"></input-number>
}
</app-form-row>
Expand Down
5 changes: 3 additions & 2 deletions src/app/tasks/new-tasks/new-tasks.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
CRACKER_VERSION_FIELD_MAPPING,
DEFAULT_FIELD_MAPPING
} from '@src/app/core/_constants/select.config';
import { benchmarkType, staticChunking } from '@src/app/core/_constants/tasks.config';
import { StaticChunkingMode, benchmarkType, staticChunking } from '@src/app/core/_constants/tasks.config';
import { CheatsheetComponent } from '@src/app/shared/alert/cheatsheet/cheatsheet.component';
import { SelectOption, transformSelectOptions } from '@src/app/shared/utils/forms';
import { AttackCommandData, NewTaskForm, getNewTaskForm } from '@src/app/tasks/new-tasks/new-tasks.form';
Expand Down Expand Up @@ -99,6 +99,7 @@ export class NewTasksComponent implements OnInit {

// Tables File Types
protected readonly FileType = FileType;
protected readonly StaticChunkingMode = StaticChunkingMode;

private formReady = false;

Expand Down Expand Up @@ -467,7 +468,7 @@ export class NewTasksComponent implements OnInit {
hashlistId: null,
skipKeyspace: 0,
crackerBinaryId: 1,
staticChunks: 0,
staticChunks: StaticChunkingMode.NONE,
chunkSize: environment.config.tasks.chunkSize,
forcePipe: false,
preprocessorId: 0,
Expand Down
3 changes: 2 additions & 1 deletion src/app/tasks/new-tasks/new-tasks.form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { CrackerBinaryId, CrackerBinaryTypeId, FileId, HashlistId, PreprocessorI

import { UIConfigService } from '@services/shared/storage.service';

import { StaticChunkingMode } from '@src/app/core/_constants/tasks.config';
import { attackCommandWithAliasValidator } from '@src/app/core/_validators/attack-command.validator';
import { environment } from '@src/environments/environment';

Expand Down Expand Up @@ -71,7 +72,7 @@ export const getNewTaskForm = (uiService: UIConfigService) => {
crackerBinaryId: new FormControl<number>(1, { nonNullable: true, validators: [Validators.required] }),
crackerBinaryTypeId: new FormControl<number | null>(null, [Validators.required]),
isArchived: new FormControl<boolean>(false, { nonNullable: true }),
staticChunks: new FormControl<number>(0, { nonNullable: true }),
staticChunks: new FormControl<number>(StaticChunkingMode.NONE, { nonNullable: true }),
chunkSize: new FormControl<number>(chunkSize, { nonNullable: true }),
forcePipe: new FormControl<boolean>(false, { nonNullable: true }),
preprocessorId: new FormControl<number>(0, { nonNullable: true }),
Expand Down
Loading