Skip to content

Commit

Permalink
Merge branch 'main' into BC-4374-submission-due-date
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfganggreschus authored Sep 19, 2023
2 parents 9f0b76a + 8cf1dca commit bce1083
Show file tree
Hide file tree
Showing 262 changed files with 6,720 additions and 2,826 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ jobs:
- name: test image exists
run: |
mkdir -p ~/.docker
echo '{"experimental": "enabled"}' >> ~/.docker/config.json
echo "IMAGE_EXISTS=$(docker manifest inspect ghcr.io/${{ github.repository }}:${{ needs.branch_meta.outputs.sha }} > /dev/null && echo 1 || echo 0)" >> $GITHUB_ENV
- name: Set up Docker Buildx
Expand Down Expand Up @@ -83,8 +81,6 @@ jobs:
- name: test image exists (file storage)
run: |
mkdir -p ~/.docker
echo '{"experimental": "enabled"}' >> ~/.docker/config.json
echo "IMAGE_EXISTS=$(docker manifest inspect ghcr.io/${{ github.repository }}:file-storage-${{ needs.branch_meta.outputs.sha }} > /dev/null && echo 1 || echo 0)" >> $GITHUB_ENV
- name: Set up Docker Buildx (file storage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,49 @@ data:

# ========== End of the Dev IServ configuration section.

# ========== Start of the Test BRB Univention LDAP system (also used on the REF BRB) configuration section.

# This is currently performed for any 'brb-*' namespace ('brb-main' for example).

if [[ "$NS" =~ ^brb-[^\s]+$ ]]; then
UNIVENTION_LDAP_SYSTEM_ID=621beef78ec63ea12a3adae6
UNIVENTION_LDAP_FEDERAL_STATE_ID=0000b186816abba584714c53

# Encrypt LDAP server's search user password.
UNIVENTION_LDAP_SEARCH_USER_PASSWORD=$(node scripts/secret.js -s $AES_KEY -e $UNIVENTION_LDAP_SEARCH_USER_PASSWORD)

# Add (or replace) document with the test BRB Univention LDAP system configuration.
mongosh $DATABASE__URL --eval 'db.systems.replaceOne(
{
"_id": ObjectId("'$UNIVENTION_LDAP_SYSTEM_ID'"),
},
{
"_id": ObjectId("'$UNIVENTION_LDAP_SYSTEM_ID'"),
"alias": "TEST BRB UNIVENTION LDAP",
"ldapConfig": {
"active": true,
"federalState": ObjectId("'$UNIVENTION_LDAP_FEDERAL_STATE_ID'"),
"url": "'$UNIVENTION_LDAP_URL'",
"rootPath": "'$UNIVENTION_LDAP_ROOT_PATH'",
"searchUser": "'$UNIVENTION_LDAP_SEARCH_USER'",
"searchUserPassword": "'$UNIVENTION_LDAP_SEARCH_USER_PASSWORD'",
"provider": "univention",
"providerOptions": {
"userAttributeNameMapping": {},
"roleAttributeNameMapping": {},
"classAttributeNameMapping": {}
}
},
"type": "ldap"
},
{
"upsert": true
}
);'
fi

# ========== End of the Test BRB Univention LDAP system (also used on the REF BRB) configuration section.

# ========== Start of the Bettermarks tool configuration section.

# This is currently performed only for the following 4 namespaces:
Expand Down
4 changes: 4 additions & 0 deletions apps/server/doc/summary.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
{
"title": "Code Style",
"file": "code-style.md"
},
{
"title": "S3ClientModule",
"file": "../src/shared/infra/s3-client/README.md"
}
]
}
Expand Down
3 changes: 3 additions & 0 deletions apps/server/src/apps/server.app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { enableOpenApiDocs } from '@shared/controller/swagger';
import { Mail, MailService } from '@shared/infra/mail';
import { LegacyLogger, Logger } from '@src/core/logger';
import { AccountService } from '@src/modules/account/services/account.service';
import { TeamService } from '@src/modules/teams/service/team.service';
import { AccountValidationService } from '@src/modules/account/services/account.validation.service';
import { AccountUc } from '@src/modules/account/uc/account.uc';
import { CollaborativeStorageUc } from '@src/modules/collaborative-storage/uc/collaborative-storage.uc';
Expand Down Expand Up @@ -76,6 +77,8 @@ async function bootstrap() {
feathersExpress.services['nest-account-uc'] = nestApp.get(AccountUc);
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
feathersExpress.services['nest-collaborative-storage-uc'] = nestApp.get(CollaborativeStorageUc);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
feathersExpress.services['nest-team-service'] = nestApp.get(TeamService);
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
feathersExpress.services['nest-orm'] = orm;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,52 +1,79 @@
import { INestApplicationContext } from '@nestjs/common';
import { BootstrapConsole, ConsoleService } from 'nestjs-console';
import { ConsoleWriterService } from '@shared/infra/console';
import { ServerConsoleModule } from '@src/console/console.module';
import { CommanderError } from 'commander';
import { execute, TestBootstrapConsole } from './test-bootstrap.console';
import { BootstrapConsole, ConsoleService } from 'nestjs-console';
import { TestBootstrapConsole, execute } from './test-bootstrap.console';

describe('DatabaseManagementConsole (API)', () => {
let app: INestApplicationContext;
let console: BootstrapConsole;
let bootstrap: BootstrapConsole;
let consoleService: ConsoleService;
beforeAll(async () => {
console = new TestBootstrapConsole({
let consoleWriter: ConsoleWriterService;

beforeEach(async () => {
bootstrap = new TestBootstrapConsole({
module: ServerConsoleModule,
useDecorators: true,
});
app = await console.init();
app = await bootstrap.init();
await app.init();
consoleService = app.get(ConsoleService);
consoleWriter = app.get(ConsoleWriterService);
});

afterAll(async () => {
afterEach(async () => {
consoleService.resetCli();
await app.close();
});

describe('Command "database"', () => {
beforeEach(() => {
const setup = () => {
const cli = consoleService.getCli('database');
const exitFn = (err: CommanderError) => {
if (err.exitCode !== 0) throw err;
};
cli?.exitOverride(exitFn);
const rootCli = consoleService.getRootCli();
rootCli.exitOverride(exitFn);
});
const spyConsoleWriterInfo = jest.spyOn(consoleWriter, 'info');
return { spyConsoleWriterInfo };
};
describe('when command not exists', () => {
it('should fail for unknown command', async () => {
setup();
await expect(execute(bootstrap, ['database', 'not_existing_command'])).rejects.toThrow(
`error: unknown command 'not_existing_command'`
);

afterEach(() => {
consoleService.resetCli();
consoleService.resetCli();
});
});

it('should fail for unknown command', async () => {
await expect(execute(console, ['database', 'not_existing_command'])).rejects.toThrow(
`error: unknown command 'not_existing_command'`
);
});
it('should provide command "seed"', async () => {
await execute(console, ['database', 'seed']);
});
it('should provide command "export"', async () => {
await execute(console, ['database', 'export']);
describe('when command exists', () => {
it('should provide command "seed"', async () => {
const { spyConsoleWriterInfo } = setup();

await execute(bootstrap, ['database', 'seed']);

expect(spyConsoleWriterInfo).toBeCalled();
});

it('should provide command "export"', async () => {
const { spyConsoleWriterInfo } = setup();

await execute(bootstrap, ['database', 'export']);

expect(spyConsoleWriterInfo).toBeCalled();
});

it('should provide command "sync-indexes"', async () => {
const { spyConsoleWriterInfo } = setup();

await execute(bootstrap, ['database', 'sync-indexes']);

expect(spyConsoleWriterInfo).toBeCalled();
});
});
});
});
10 changes: 9 additions & 1 deletion apps/server/src/console/api-test/test-bootstrap.console.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import { createMock } from '@golevelup/ts-jest';
import { Test, TestingModule } from '@nestjs/testing';
import { ConsoleWriterService } from '@shared/infra/console';
import { DatabaseManagementUc } from '@src/modules/management/uc/database-management.uc';
import { AbstractBootstrapConsole, BootstrapConsole } from 'nestjs-console';

export class TestBootstrapConsole extends AbstractBootstrapConsole<TestingModule> {
create(): Promise<TestingModule> {
return Test.createTestingModule({
imports: [this.options.module],
}).compile();
})
.overrideProvider(DatabaseManagementUc)
.useValue(createMock<DatabaseManagementUc>())
.overrideProvider(ConsoleWriterService)
.useValue(createMock<ConsoleWriterService>())
.compile();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { JwtModule, JwtModuleOptions } from '@nestjs/jwt';
import { PassportModule } from '@nestjs/passport';
import { CacheWrapperModule } from '@shared/infra/cache';
import { IdentityManagementModule } from '@shared/infra/identity-management';
import { LegacySchoolRepo, SystemRepo, UserRepo } from '@shared/repo';
import { SchoolRepo, SystemRepo, UserRepo } from '@shared/repo';
import { LoggerModule } from '@src/core/logger';
import { AccountModule } from '@src/modules/account';
import { OauthModule } from '@src/modules/oauth/oauth.module';
Expand Down Expand Up @@ -70,7 +70,7 @@ const jwtModuleOptions: JwtModuleOptions = {
JwtValidationAdapter,
UserRepo,
SystemRepo,
LegacySchoolRepo,
SchoolRepo,
LocalStrategy,
AuthenticationService,
LdapService,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createMock, DeepMocked } from '@golevelup/ts-jest';
import { ObjectId } from '@mikro-orm/mongodb';
import { CACHE_MANAGER } from '@nestjs/common';
import { CACHE_MANAGER } from '@nestjs/cache-manager';
import { Test, TestingModule } from '@nestjs/testing';
import { CacheService } from '@shared/infra/cache';
import { CacheStoreType } from '@shared/infra/cache/interface/cache-store-type.enum';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CACHE_MANAGER, Inject, Injectable } from '@nestjs/common';
import { CACHE_MANAGER } from '@nestjs/cache-manager';
import { Inject, Injectable } from '@nestjs/common';
import { CacheService } from '@shared/infra/cache';
import { CacheStoreType } from '@shared/infra/cache/interface/cache-store-type.enum';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest';
import { UnauthorizedException } from '@nestjs/common';
import { PassportModule } from '@nestjs/passport';
import { Test, TestingModule } from '@nestjs/testing';
import { LegacySchoolDo, RoleName, System, User } from '@shared/domain';
import { LegacySchoolRepo, SystemRepo, UserRepo } from '@shared/repo';
import { RoleName, System, User } from '@shared/domain';
import { SchoolDO } from '@shared/domain/domainobject/school.do';
import { SchoolRepo, SystemRepo, UserRepo } from '@shared/repo';
import {
accountDtoFactory,
defaultTestPassword,
defaultTestPasswordHash,
legacySchoolDoFactory,
schoolDOFactory,
schoolFactory,
setupEntities,
systemFactory,
Expand All @@ -27,7 +28,7 @@ describe('LdapStrategy', () => {
let strategy: LdapStrategy;

let userRepoMock: DeepMocked<UserRepo>;
let schoolRepoMock: DeepMocked<LegacySchoolRepo>;
let schoolRepoMock: DeepMocked<SchoolRepo>;
let authenticationServiceMock: DeepMocked<AuthenticationService>;
let ldapServiceMock: DeepMocked<LdapService>;
let systemRepo: DeepMocked<SystemRepo>;
Expand All @@ -52,8 +53,8 @@ describe('LdapStrategy', () => {
useValue: createMock<UserRepo>(),
},
{
provide: LegacySchoolRepo,
useValue: createMock<LegacySchoolRepo>(),
provide: SchoolRepo,
useValue: createMock<SchoolRepo>(),
},
{
provide: SystemRepo,
Expand All @@ -68,7 +69,7 @@ describe('LdapStrategy', () => {

strategy = module.get(LdapStrategy);
authenticationServiceMock = module.get(AuthenticationService);
schoolRepoMock = module.get(LegacySchoolRepo);
schoolRepoMock = module.get(SchoolRepo);
userRepoMock = module.get(UserRepo);
ldapServiceMock = module.get(LdapService);
systemRepo = module.get(SystemRepo);
Expand All @@ -91,7 +92,7 @@ describe('LdapStrategy', () => {

const user: User = userFactory.withRoleByName(RoleName.STUDENT).buildWithId({ ldapDn: undefined });

const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId({ systems: [system.id] }, user.school.id);
const school: SchoolDO = schoolDOFactory.buildWithId({ systems: [system.id] }, user.school.id);

const account: AccountDto = accountDtoFactory.build({
systemId: system.id,
Expand Down Expand Up @@ -138,7 +139,7 @@ describe('LdapStrategy', () => {

const user: User = userFactory.withRoleByName(RoleName.STUDENT).buildWithId({ ldapDn: 'mockLdapDn' });

const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId({ systems: [] }, user.school.id);
const school: SchoolDO = schoolDOFactory.buildWithId({ systems: [] }, user.school.id);

const account: AccountDto = accountDtoFactory.build({
systemId: system.id,
Expand Down Expand Up @@ -185,7 +186,7 @@ describe('LdapStrategy', () => {

const user: User = userFactory.withRoleByName(RoleName.STUDENT).buildWithId({ ldapDn: 'mockLdapDn' });

const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId({ systems: undefined }, user.school.id);
const school: SchoolDO = schoolDOFactory.buildWithId({ systems: undefined }, user.school.id);

const account: AccountDto = accountDtoFactory.build({
systemId: system.id,
Expand Down Expand Up @@ -232,7 +233,7 @@ describe('LdapStrategy', () => {

const user: User = userFactory.withRoleByName(RoleName.STUDENT).buildWithId({ ldapDn: 'mockLdapDn' });

const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId({ systems: [system.id] }, user.school.id);
const school: SchoolDO = schoolDOFactory.buildWithId({ systems: [system.id] }, user.school.id);

const account: AccountDto = accountDtoFactory.build({
systemId: system.id,
Expand Down Expand Up @@ -279,7 +280,7 @@ describe('LdapStrategy', () => {

const user: User = userFactory.withRoleByName(RoleName.STUDENT).buildWithId({ ldapDn: 'mockLdapDn' });

const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId({ systems: [system.id] }, user.school.id);
const school: SchoolDO = schoolDOFactory.buildWithId({ systems: [system.id] }, user.school.id);

const account: AccountDto = accountDtoFactory.build({
systemId: system.id,
Expand Down Expand Up @@ -331,7 +332,7 @@ describe('LdapStrategy', () => {

const user: User = userFactory.withRoleByName(RoleName.STUDENT).buildWithId({ ldapDn: 'mockLdapDn' });

const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId({ systems: [system.id] }, user.school.id);
const school: SchoolDO = schoolDOFactory.buildWithId({ systems: [system.id] }, user.school.id);

const account: AccountDto = accountDtoFactory.build({
systemId: system.id,
Expand Down Expand Up @@ -388,7 +389,7 @@ describe('LdapStrategy', () => {
.withRoleByName(RoleName.STUDENT)
.buildWithId({ ldapDn: 'mockLdapDn', school: schoolFactory.buildWithId() });

const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId(
const school: SchoolDO = schoolDOFactory.buildWithId(
{ systems: [system.id], previousExternalId: undefined },
user.school.id
);
Expand Down Expand Up @@ -450,7 +451,7 @@ describe('LdapStrategy', () => {
.withRoleByName(RoleName.STUDENT)
.buildWithId({ ldapDn: 'mockLdapDn', school: schoolFactory.buildWithId() });

const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId(
const school: SchoolDO = schoolDOFactory.buildWithId(
{ systems: [system.id], previousExternalId: 'previousExternalId' },
user.school.id
);
Expand Down
Loading

0 comments on commit bce1083

Please sign in to comment.