@mudrichenkoevgeny/web-platform-sdk-core-security 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -201
- package/README.md +110 -110
- package/dist/di/security-component.d.ts +56 -0
- package/dist/di/security-component.d.ts.map +1 -0
- package/dist/di/security-component.test.d.ts +2 -0
- package/dist/di/security-component.test.d.ts.map +1 -0
- package/dist/error/model/security-error.d.ts +117 -0
- package/dist/error/model/security-error.d.ts.map +1 -0
- package/dist/error/model/security-error.test.d.ts +2 -0
- package/dist/error/model/security-error.test.d.ts.map +1 -0
- package/dist/error/parser/security-error-parser.d.ts +37 -0
- package/dist/error/parser/security-error-parser.d.ts.map +1 -0
- package/dist/error/parser/security-error-parser.test.d.ts +2 -0
- package/dist/error/parser/security-error-parser.test.d.ts.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12255 -5155
- package/dist/integration/SecuritySettingsIntegration.test.d.ts +2 -0
- package/dist/integration/SecuritySettingsIntegration.test.d.ts.map +1 -0
- package/dist/mock/di/security-component-mock.d.ts +9 -0
- package/dist/mock/di/security-component-mock.d.ts.map +1 -0
- package/dist/mock/network/open-security-settings-api-mock.d.ts +25 -0
- package/dist/mock/network/open-security-settings-api-mock.d.ts.map +1 -0
- package/dist/mock/repository/open-security-settings-repository-mock.d.ts +28 -0
- package/dist/mock/repository/open-security-settings-repository-mock.d.ts.map +1 -0
- package/dist/mock/storage/open-security-settings-storage-mock.d.ts +31 -0
- package/dist/mock/storage/open-security-settings-storage-mock.d.ts.map +1 -0
- package/dist/mock/usecase/validate-password-use-case-mock.d.ts +22 -0
- package/dist/mock/usecase/validate-password-use-case-mock.d.ts.map +1 -0
- package/dist/network/api/security-settings/fetch-open-security-settings-api.d.ts +22 -0
- package/dist/network/api/security-settings/fetch-open-security-settings-api.d.ts.map +1 -0
- package/dist/network/api/security-settings/fetch-open-security-settings-api.test.d.ts +2 -0
- package/dist/network/api/security-settings/fetch-open-security-settings-api.test.d.ts.map +1 -0
- package/dist/network/api/security-settings/open-security-settings-api.d.ts +14 -0
- package/dist/network/api/security-settings/open-security-settings-api.d.ts.map +1 -0
- package/dist/network/api/security-settings/security-settings-dto-mapping.test.d.ts +2 -0
- package/dist/network/api/security-settings/security-settings-dto-mapping.test.d.ts.map +1 -0
- package/dist/network/contract/security-web-socket-event-types.d.ts +2 -0
- package/dist/network/contract/security-web-socket-event-types.d.ts.map +1 -0
- package/dist/network/websocket/message-handler/security-web-socket-message-handler.d.ts +15 -0
- package/dist/network/websocket/message-handler/security-web-socket-message-handler.d.ts.map +1 -0
- package/dist/network/websocket/message-handler/security-web-socket-message-handler.test.d.ts +2 -0
- package/dist/network/websocket/message-handler/security-web-socket-message-handler.test.d.ts.map +1 -0
- package/dist/repository/open-security-settings-repository-impl.d.ts +57 -0
- package/dist/repository/open-security-settings-repository-impl.d.ts.map +1 -0
- package/dist/repository/open-security-settings-repository-impl.test.d.ts +2 -0
- package/dist/repository/open-security-settings-repository-impl.test.d.ts.map +1 -0
- package/dist/repository/open-security-settings-repository.d.ts +35 -0
- package/dist/repository/open-security-settings-repository.d.ts.map +1 -0
- package/dist/storage/security-settings/encrypted-open-security-settings-storage.d.ts +32 -0
- package/dist/storage/security-settings/encrypted-open-security-settings-storage.d.ts.map +1 -0
- package/dist/storage/security-settings/encrypted-open-security-settings-storage.test.d.ts +2 -0
- package/dist/storage/security-settings/encrypted-open-security-settings-storage.test.d.ts.map +1 -0
- package/dist/storage/security-settings/open-security-settings-storage.d.ts +23 -0
- package/dist/storage/security-settings/open-security-settings-storage.d.ts.map +1 -0
- package/dist/usecase/observe-open-security-settings-use-case.d.ts +19 -0
- package/dist/usecase/observe-open-security-settings-use-case.d.ts.map +1 -0
- package/dist/usecase/observe-open-security-settings-use-case.test.d.ts +2 -0
- package/dist/usecase/observe-open-security-settings-use-case.test.d.ts.map +1 -0
- package/dist/usecase/refresh-open-security-settings-use-case.d.ts +22 -0
- package/dist/usecase/refresh-open-security-settings-use-case.d.ts.map +1 -0
- package/dist/usecase/refresh-open-security-settings-use-case.test.d.ts +2 -0
- package/dist/usecase/refresh-open-security-settings-use-case.test.d.ts.map +1 -0
- package/dist/usecase/validate-password-use-case.d.ts +26 -0
- package/dist/usecase/validate-password-use-case.d.ts.map +1 -0
- package/dist/usecase/validate-password-use-case.test.d.ts +2 -0
- package/dist/usecase/validate-password-use-case.test.d.ts.map +1 -0
- package/package.json +16 -7
- package/src/di/security-component.test.ts +0 -33
- package/src/di/security-component.ts +0 -86
- package/src/domain/model/open-security-settings.ts +0 -79
- package/src/domain/model/password-policy-validator.test.ts +0 -96
- package/src/domain/model/password-policy-validator.ts +0 -63
- package/src/error/model/security-error.test.ts +0 -65
- package/src/error/model/security-error.ts +0 -182
- package/src/error/naming/client-security-error-codes.ts +0 -21
- package/src/error/parser/security-error-parser.test.ts +0 -87
- package/src/error/parser/security-error-parser.ts +0 -138
- package/src/index.ts +0 -24
- package/src/locales/en/strings.ts +0 -67
- package/src/locales/index.ts +0 -2
- package/src/locales/ru/strings.ts +0 -35
- package/src/mock/di/security-component-mock.ts +0 -35
- package/src/mock/domain/model/open-security-settings-mock.ts +0 -52
- package/src/mock/network/model/open-security-settings-payload-mock.ts +0 -28
- package/src/mock/network/open-security-settings-api-mock.ts +0 -38
- package/src/mock/repository/open-security-settings-repository-mock.ts +0 -62
- package/src/mock/storage/open-security-settings-storage-mock.ts +0 -45
- package/src/mock/usecase/validate-password-use-case-mock.ts +0 -31
- package/src/network/contract/security-web-socket-event-types.ts +0 -7
- package/src/network/security-settings/fetch-open-security-settings-api.test.ts +0 -51
- package/src/network/security-settings/fetch-open-security-settings-api.ts +0 -30
- package/src/network/security-settings/open-security-settings-api.ts +0 -15
- package/src/network/websocket/message-handler/security-web-socket-message-handler.test.ts +0 -19
- package/src/network/websocket/message-handler/security-web-socket-message-handler.ts +0 -19
- package/src/repository/open-security-settings-repository-impl.test.ts +0 -112
- package/src/repository/open-security-settings-repository-impl.ts +0 -151
- package/src/repository/open-security-settings-repository.ts +0 -39
- package/src/storage/security-settings/encrypted-open-security-settings-storage.test.ts +0 -71
- package/src/storage/security-settings/encrypted-open-security-settings-storage.ts +0 -65
- package/src/storage/security-settings/open-security-settings-storage.ts +0 -25
- package/src/usecase/refresh-open-security-settings-use-case.ts +0 -26
- package/src/usecase/security-use-cases.test.ts +0 -67
- package/src/usecase/validate-password-use-case.ts +0 -76
- package/tsconfig.json +0 -16
- package/vite.config.ts +0 -50
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest'
|
|
2
|
-
import { RefreshOpenSecuritySettingsUseCase } from '@/usecase/refresh-open-security-settings-use-case'
|
|
3
|
-
import { ValidatePasswordUseCase } from '@/usecase/validate-password-use-case'
|
|
4
|
-
import { PasswordPolicyValidator } from '@/domain/model/password-policy-validator'
|
|
5
|
-
import { OpenSecuritySettingsRepositoryMock } from '@/mock/repository/open-security-settings-repository-mock'
|
|
6
|
-
import { ClientSecurityErrorCodes } from '@/error/naming/client-security-error-codes'
|
|
7
|
-
import type { SecurityError } from '@/error/model/security-error'
|
|
8
|
-
|
|
9
|
-
describe('Security Use Cases', () => {
|
|
10
|
-
describe('RefreshOpenSecuritySettingsUseCase', () => {
|
|
11
|
-
it('delegates to repository refresh method', async () => {
|
|
12
|
-
const repo = new OpenSecuritySettingsRepositoryMock()
|
|
13
|
-
const useCase = new RefreshOpenSecuritySettingsUseCase(repo)
|
|
14
|
-
|
|
15
|
-
expect(repo.refreshCallCount).toBe(0)
|
|
16
|
-
const result = await useCase.execute()
|
|
17
|
-
|
|
18
|
-
expect(repo.refreshCallCount).toBe(1)
|
|
19
|
-
expect(result.success).toBe(true)
|
|
20
|
-
})
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
describe('ValidatePasswordUseCase', () => {
|
|
24
|
-
it('validates password successfully using repository policy', async () => {
|
|
25
|
-
const repo = new OpenSecuritySettingsRepositoryMock()
|
|
26
|
-
const validator = new PasswordPolicyValidator()
|
|
27
|
-
const useCase = new ValidatePasswordUseCase(repo, validator)
|
|
28
|
-
|
|
29
|
-
const result = await useCase.execute('Valid123!')
|
|
30
|
-
expect(result.success).toBe(true)
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
it('returns SecurityError if password fails validation', async () => {
|
|
34
|
-
const repo = new OpenSecuritySettingsRepositoryMock()
|
|
35
|
-
const validator = new PasswordPolicyValidator()
|
|
36
|
-
const useCase = new ValidatePasswordUseCase(repo, validator)
|
|
37
|
-
|
|
38
|
-
const result = await useCase.execute('short')
|
|
39
|
-
expect(result.success).toBe(false)
|
|
40
|
-
if (!result.success) {
|
|
41
|
-
expect((result.error as SecurityError).code).toBe(ClientSecurityErrorCodes.PASSWORD_TOO_SHORT)
|
|
42
|
-
}
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
it('uses fallback policy if repository fetch fails', async () => {
|
|
46
|
-
const repo = new OpenSecuritySettingsRepositoryMock({ shouldFailGet: true })
|
|
47
|
-
const validator = new PasswordPolicyValidator()
|
|
48
|
-
const useCase = new ValidatePasswordUseCase(repo, validator)
|
|
49
|
-
|
|
50
|
-
// Fallback policy requires min length 8 and a letter.
|
|
51
|
-
const resultShort = await useCase.execute('1234567')
|
|
52
|
-
expect(resultShort.success).toBe(false)
|
|
53
|
-
if (!resultShort.success) {
|
|
54
|
-
expect((resultShort.error as SecurityError).code).toBe(ClientSecurityErrorCodes.PASSWORD_TOO_SHORT)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const resultNoLetter = await useCase.execute('12345678')
|
|
58
|
-
expect(resultNoLetter.success).toBe(false)
|
|
59
|
-
if (!resultNoLetter.success) {
|
|
60
|
-
expect((resultNoLetter.error as SecurityError).code).toBe(ClientSecurityErrorCodes.PASSWORD_NO_LETTER)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const resultValid = await useCase.execute('a1234567')
|
|
64
|
-
expect(resultValid.success).toBe(true)
|
|
65
|
-
})
|
|
66
|
-
})
|
|
67
|
-
})
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import type { AppResult, AppError } from '@mudrichenkoevgeny/web-platform-sdk-core-common'
|
|
2
|
-
import type { OpenSecuritySettingsRepository } from '@/repository/open-security-settings-repository'
|
|
3
|
-
import type { PasswordPolicyValidator, PasswordPolicyFailReason } from '@/domain/model/password-policy-validator'
|
|
4
|
-
import { SecurityError } from '@/error/model/security-error'
|
|
5
|
-
import type { OpenPasswordPolicy } from '@/domain/model/open-security-settings'
|
|
6
|
-
|
|
7
|
-
/** Default fallback password policy if loading from repository fails. */
|
|
8
|
-
const FALLBACK_PASSWORD_POLICY: OpenPasswordPolicy = {
|
|
9
|
-
minLength: 8,
|
|
10
|
-
requireLetter: true,
|
|
11
|
-
requireUpperCase: false,
|
|
12
|
-
requireLowerCase: false,
|
|
13
|
-
requireDigit: false,
|
|
14
|
-
requireSpecialChar: false
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Validates a password string against the current {@link OpenPasswordPolicy} from {@link OpenSecuritySettingsRepository}.
|
|
19
|
-
*/
|
|
20
|
-
export class ValidatePasswordUseCase {
|
|
21
|
-
/**
|
|
22
|
-
* Constructs a new {@link ValidatePasswordUseCase}.
|
|
23
|
-
*
|
|
24
|
-
* @param openSecuritySettingsRepository - Source of the active password policy
|
|
25
|
-
* @param passwordPolicyValidator - Pure domain logic validator implementation
|
|
26
|
-
*/
|
|
27
|
-
public constructor(
|
|
28
|
-
private readonly openSecuritySettingsRepository: OpenSecuritySettingsRepository,
|
|
29
|
-
private readonly passwordPolicyValidator: PasswordPolicyValidator
|
|
30
|
-
) {}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Evaluates the candidate password.
|
|
34
|
-
*
|
|
35
|
-
* @param password - Candidate password to validate
|
|
36
|
-
* @returns AppResult resolving to void on success, or SecurityError on failure
|
|
37
|
-
*/
|
|
38
|
-
public async execute(password: string): Promise<AppResult<void, AppError>> {
|
|
39
|
-
const securitySettingsResult = await this.openSecuritySettingsRepository.getOpenSecuritySettings()
|
|
40
|
-
|
|
41
|
-
const passwordPolicy = securitySettingsResult.success
|
|
42
|
-
? securitySettingsResult.data.openPasswordPolicy
|
|
43
|
-
: FALLBACK_PASSWORD_POLICY
|
|
44
|
-
|
|
45
|
-
const validationResult = this.passwordPolicyValidator.validate(passwordPolicy, password)
|
|
46
|
-
|
|
47
|
-
if (validationResult.success) {
|
|
48
|
-
return { success: true, data: undefined }
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const primaryReason = validationResult.reasons[0] as PasswordPolicyFailReason
|
|
52
|
-
return {
|
|
53
|
-
success: false,
|
|
54
|
-
error: this.toSecurityError(primaryReason, passwordPolicy.minLength)
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
private toSecurityError(reason: PasswordPolicyFailReason, minLength: number): SecurityError {
|
|
59
|
-
switch (reason) {
|
|
60
|
-
case 'TOO_SHORT':
|
|
61
|
-
return SecurityError.passwordTooShort(minLength)
|
|
62
|
-
case 'NO_LETTER':
|
|
63
|
-
return SecurityError.passwordNoLetter()
|
|
64
|
-
case 'NO_UPPERCASE':
|
|
65
|
-
return SecurityError.passwordNoUpperCase()
|
|
66
|
-
case 'NO_LOWERCASE':
|
|
67
|
-
return SecurityError.passwordNoLowerCase()
|
|
68
|
-
case 'NO_DIGIT':
|
|
69
|
-
return SecurityError.passwordNoDigit()
|
|
70
|
-
case 'NO_SPECIAL_CHAR':
|
|
71
|
-
return SecurityError.passwordNoSpecialChar()
|
|
72
|
-
case 'TOO_COMMON':
|
|
73
|
-
return SecurityError.passwordTooCommon()
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.base.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "./dist",
|
|
5
|
-
"rootDir": "./src",
|
|
6
|
-
"jsx": "react-jsx",
|
|
7
|
-
"declaration": true,
|
|
8
|
-
"declarationMap": true,
|
|
9
|
-
"paths": {
|
|
10
|
-
"@/*": ["./src/*"]
|
|
11
|
-
}
|
|
12
|
-
},
|
|
13
|
-
"include": [
|
|
14
|
-
"src/**/*"
|
|
15
|
-
]
|
|
16
|
-
}
|
package/vite.config.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from 'vite'
|
|
2
|
-
import svgr from 'vite-plugin-svgr'
|
|
3
|
-
import dts from 'vite-plugin-dts'
|
|
4
|
-
import { fileURLToPath, URL } from 'node:url'
|
|
5
|
-
|
|
6
|
-
export default defineConfig(({ command, mode }) => {
|
|
7
|
-
const isTest = mode === 'test' || process.env.NODE_ENV === 'test'
|
|
8
|
-
const plugins = [
|
|
9
|
-
svgr({
|
|
10
|
-
svgrOptions: {
|
|
11
|
-
icon: true
|
|
12
|
-
}
|
|
13
|
-
})
|
|
14
|
-
]
|
|
15
|
-
|
|
16
|
-
if (!isTest && command === 'build') {
|
|
17
|
-
plugins.push(dts({ rollupTypes: true }))
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return {
|
|
21
|
-
plugins,
|
|
22
|
-
resolve: {
|
|
23
|
-
alias: {
|
|
24
|
-
'@': fileURLToPath(new URL('./src', import.meta.url))
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
test: {
|
|
28
|
-
name: 'core-security',
|
|
29
|
-
globals: true,
|
|
30
|
-
environment: 'jsdom',
|
|
31
|
-
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
|
|
32
|
-
server: {
|
|
33
|
-
deps: {
|
|
34
|
-
inline: ['@mudrichenkoevgeny/shared-foundation']
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
build: {
|
|
39
|
-
lib: {
|
|
40
|
-
entry: './src/index.ts',
|
|
41
|
-
name: 'WebPlatformSdkCoreSecurity',
|
|
42
|
-
fileName: 'index',
|
|
43
|
-
formats: ['es']
|
|
44
|
-
},
|
|
45
|
-
rollupOptions: {
|
|
46
|
-
external: ['react', 'react-dom', 'react/jsx-runtime']
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
})
|