618d4d674f
- Implement unit tests for password handling in `auth_test.ts`, covering bcrypt and legacy password hashes. - Create a fake database for user management to facilitate testing of the `AdminHandler`. - Validate JWT-based identity verification against database records. - Introduce tests for credential encryption and registry management in `security_test.ts`. - Ensure registry passwords are securely stored and can be decrypted correctly, including legacy support. - Add utility functions for password hashing and verification in `auth.ts`.
66 lines
2.4 KiB
TypeScript
66 lines
2.4 KiB
TypeScript
import * as plugins from '../../plugins.ts';
|
|
import type { OpsServer } from '../classes.opsserver.ts';
|
|
import * as interfaces from '../../../ts_interfaces/index.ts';
|
|
import { requireAdminIdentity } from '../helpers/guards.ts';
|
|
|
|
export class DnsHandler {
|
|
public typedrouter = new plugins.typedrequest.TypedRouter();
|
|
|
|
constructor(private opsServerRef: OpsServer) {
|
|
this.opsServerRef.typedrouter.addTypedRouter(this.typedrouter);
|
|
this.registerHandlers();
|
|
}
|
|
|
|
private registerHandlers(): void {
|
|
this.typedrouter.addTypedHandler(
|
|
new plugins.typedrequest.TypedHandler<interfaces.requests.IReq_GetDnsRecords>(
|
|
'getDnsRecords',
|
|
async (dataArg) => {
|
|
await requireAdminIdentity(this.opsServerRef.adminHandler, dataArg);
|
|
const records = this.opsServerRef.oneboxRef.dns.listDNSRecords();
|
|
return { records };
|
|
},
|
|
),
|
|
);
|
|
|
|
this.typedrouter.addTypedHandler(
|
|
new plugins.typedrequest.TypedHandler<interfaces.requests.IReq_CreateDnsRecord>(
|
|
'createDnsRecord',
|
|
async (dataArg) => {
|
|
await requireAdminIdentity(this.opsServerRef.adminHandler, dataArg);
|
|
await this.opsServerRef.oneboxRef.dns.addDNSRecord(dataArg.domain, dataArg.value);
|
|
const records = this.opsServerRef.oneboxRef.dns.listDNSRecords();
|
|
const record = records.find((r: any) => r.domain === dataArg.domain);
|
|
return { record: record! };
|
|
},
|
|
),
|
|
);
|
|
|
|
this.typedrouter.addTypedHandler(
|
|
new plugins.typedrequest.TypedHandler<interfaces.requests.IReq_DeleteDnsRecord>(
|
|
'deleteDnsRecord',
|
|
async (dataArg) => {
|
|
await requireAdminIdentity(this.opsServerRef.adminHandler, dataArg);
|
|
await this.opsServerRef.oneboxRef.dns.removeDNSRecord(dataArg.domain);
|
|
return { ok: true };
|
|
},
|
|
),
|
|
);
|
|
|
|
this.typedrouter.addTypedHandler(
|
|
new plugins.typedrequest.TypedHandler<interfaces.requests.IReq_SyncDns>(
|
|
'syncDns',
|
|
async (dataArg) => {
|
|
await requireAdminIdentity(this.opsServerRef.adminHandler, dataArg);
|
|
if (!this.opsServerRef.oneboxRef.dns.isConfigured()) {
|
|
throw new plugins.typedrequest.TypedResponseError('DNS manager not configured');
|
|
}
|
|
await this.opsServerRef.oneboxRef.dns.syncFromCloudflare();
|
|
const records = this.opsServerRef.oneboxRef.dns.listDNSRecords();
|
|
return { records };
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|