@jmlq/auth 0.0.1-alpha.1
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/README.md +306 -0
- package/dist/examples/bcrypt-password-hasher.example.d.ts +3 -0
- package/dist/examples/bcrypt-password-hasher.example.js +78 -0
- package/dist/examples/entity-object.example.d.ts +39 -0
- package/dist/examples/entity-object.example.js +411 -0
- package/dist/examples/factory-auth-service-example.d.ts +3 -0
- package/dist/examples/factory-auth-service-example.js +84 -0
- package/dist/examples/index.example.d.ts +12 -0
- package/dist/examples/index.example.js +171 -0
- package/dist/examples/jwt-algoritm.example.d.ts +47 -0
- package/dist/examples/jwt-algoritm.example.js +447 -0
- package/dist/examples/jwt-token-generator.example.d.ts +6 -0
- package/dist/examples/jwt-token-generator.example.js +49 -0
- package/dist/examples/jwt-verifier.example.d.ts +3 -0
- package/dist/examples/jwt-verifier.example.js +80 -0
- package/dist/examples/password-policy.example.d.ts +7 -0
- package/dist/examples/password-policy.example.js +57 -0
- package/dist/examples/service-jwt-token.example.d.ts +3 -0
- package/dist/examples/service-jwt-token.example.js +154 -0
- package/dist/examples/service-token-session.example.d.ts +3 -0
- package/dist/examples/service-token-session.example.js +139 -0
- package/dist/examples/use-case-login-with-password.example.d.ts +6 -0
- package/dist/examples/use-case-login-with-password.example.js +105 -0
- package/dist/examples/use-case-logout.example.d.ts +7 -0
- package/dist/examples/use-case-logout.example.js +134 -0
- package/dist/examples/use-case-refresh-token.example.d.ts +11 -0
- package/dist/examples/use-case-refresh-token.example.js +164 -0
- package/dist/examples/use-case-register-user.example.d.ts +9 -0
- package/dist/examples/use-case-register-user.example.js +110 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +17 -0
- package/dist/src/application/dtos/index.d.ts +4 -0
- package/dist/src/application/dtos/index.js +20 -0
- package/dist/src/application/dtos/login.dto.d.ts +9 -0
- package/dist/src/application/dtos/login.dto.js +2 -0
- package/dist/src/application/dtos/logout.dto.d.ts +7 -0
- package/dist/src/application/dtos/logout.dto.js +2 -0
- package/dist/src/application/dtos/refresh-token.dto.d.ts +7 -0
- package/dist/src/application/dtos/refresh-token.dto.js +2 -0
- package/dist/src/application/dtos/register-user.dto.d.ts +16 -0
- package/dist/src/application/dtos/register-user.dto.js +2 -0
- package/dist/src/application/factories/auth-service.factory.d.ts +5 -0
- package/dist/src/application/factories/auth-service.factory.js +51 -0
- package/dist/src/application/factories/index.d.ts +1 -0
- package/dist/src/application/factories/index.js +17 -0
- package/dist/src/application/index.d.ts +3 -0
- package/dist/src/application/index.js +19 -0
- package/dist/src/application/use-cases/index.d.ts +4 -0
- package/dist/src/application/use-cases/index.js +20 -0
- package/dist/src/application/use-cases/login-with-password.use-case.d.ts +9 -0
- package/dist/src/application/use-cases/login-with-password.use-case.js +36 -0
- package/dist/src/application/use-cases/logout.use-case.d.ts +7 -0
- package/dist/src/application/use-cases/logout.use-case.js +22 -0
- package/dist/src/application/use-cases/refresh-token.use-case.d.ts +7 -0
- package/dist/src/application/use-cases/refresh-token.use-case.js +23 -0
- package/dist/src/application/use-cases/register-user.use-case.d.ts +10 -0
- package/dist/src/application/use-cases/register-user.use-case.js +37 -0
- package/dist/src/domain/entities/credential.entity.d.ts +78 -0
- package/dist/src/domain/entities/credential.entity.js +92 -0
- package/dist/src/domain/entities/index.d.ts +2 -0
- package/dist/src/domain/entities/index.js +18 -0
- package/dist/src/domain/entities/user.entity.d.ts +97 -0
- package/dist/src/domain/entities/user.entity.js +116 -0
- package/dist/src/domain/errors/auth-domain-error.d.ts +82 -0
- package/dist/src/domain/errors/auth-domain-error.js +112 -0
- package/dist/src/domain/errors/auth.errors.d.ts +56 -0
- package/dist/src/domain/errors/auth.errors.js +76 -0
- package/dist/src/domain/errors/identity.errors.d.ts +34 -0
- package/dist/src/domain/errors/identity.errors.js +82 -0
- package/dist/src/domain/errors/index.d.ts +2 -0
- package/dist/src/domain/errors/index.js +18 -0
- package/dist/src/domain/index.d.ts +6 -0
- package/dist/src/domain/index.js +22 -0
- package/dist/src/domain/object-values/email.d.ts +37 -0
- package/dist/src/domain/object-values/email.js +56 -0
- package/dist/src/domain/object-values/hashed-password.d.ts +28 -0
- package/dist/src/domain/object-values/hashed-password.js +73 -0
- package/dist/src/domain/object-values/id.d.ts +8 -0
- package/dist/src/domain/object-values/id.js +28 -0
- package/dist/src/domain/object-values/index.d.ts +5 -0
- package/dist/src/domain/object-values/index.js +13 -0
- package/dist/src/domain/object-values/permission.d.ts +15 -0
- package/dist/src/domain/object-values/permission.js +57 -0
- package/dist/src/domain/object-values/role.d.ts +25 -0
- package/dist/src/domain/object-values/role.js +108 -0
- package/dist/src/domain/ports/auth/password-hasher.d.ts +7 -0
- package/dist/src/domain/ports/auth/password-hasher.js +2 -0
- package/dist/src/domain/ports/auth/password-policy-config.port.d.ts +0 -0
- package/dist/src/domain/ports/auth/password-policy-config.port.js +10 -0
- package/dist/src/domain/ports/auth/password-policy.port.d.ts +10 -0
- package/dist/src/domain/ports/auth/password-policy.port.js +2 -0
- package/dist/src/domain/ports/config/auth-config.port.d.ts +19 -0
- package/dist/src/domain/ports/config/auth-config.port.js +3 -0
- package/dist/src/domain/ports/index.d.ts +9 -0
- package/dist/src/domain/ports/index.js +25 -0
- package/dist/src/domain/ports/jwt/factory/signature-strategy-factory.port.d.ts +14 -0
- package/dist/src/domain/ports/jwt/factory/signature-strategy-factory.port.js +2 -0
- package/dist/src/domain/ports/jwt/payload/jwt-payload.port.d.ts +12 -0
- package/dist/src/domain/ports/jwt/payload/jwt-payload.port.js +2 -0
- package/dist/src/domain/ports/jwt/signature-strategy-factory.port.d.ts +14 -0
- package/dist/src/domain/ports/jwt/signature-strategy-factory.port.js +2 -0
- package/dist/src/domain/ports/jwt/signature-strategy.d.ts +30 -0
- package/dist/src/domain/ports/jwt/signature-strategy.js +4 -0
- package/dist/src/domain/ports/jwt/signature-strategy.port.d.ts +31 -0
- package/dist/src/domain/ports/jwt/signature-strategy.port.js +4 -0
- package/dist/src/domain/ports/jwt/strategy/signature-strategy.port.d.ts +31 -0
- package/dist/src/domain/ports/jwt/strategy/signature-strategy.port.js +4 -0
- package/dist/src/domain/ports/repository/credential.repository.d.ts +10 -0
- package/dist/src/domain/ports/repository/credential.repository.js +2 -0
- package/dist/src/domain/ports/repository/index.d.ts +2 -0
- package/dist/src/domain/ports/repository/index.js +18 -0
- package/dist/src/domain/ports/repository/user.repository.d.ts +13 -0
- package/dist/src/domain/ports/repository/user.repository.js +2 -0
- package/dist/src/domain/ports/token/token-session.port.d.ts +7 -0
- package/dist/src/domain/ports/token/token-session.port.js +2 -0
- package/dist/src/domain/ports/token/token.service.port.d.ts +9 -0
- package/dist/src/domain/ports/token/token.service.port.js +2 -0
- package/dist/src/domain/props/create-payload-props.port.d.ts +0 -0
- package/dist/src/domain/props/create-payload-props.port.js +8 -0
- package/dist/src/domain/props/entities/credential.props.d.ts +8 -0
- package/dist/src/domain/props/entities/credential.props.js +2 -0
- package/dist/src/domain/props/entities/index.d.ts +2 -0
- package/dist/src/domain/props/entities/index.js +18 -0
- package/dist/src/domain/props/entities/user.props.d.ts +10 -0
- package/dist/src/domain/props/entities/user.props.js +2 -0
- package/dist/src/domain/props/index.d.ts +2 -0
- package/dist/src/domain/props/index.js +18 -0
- package/dist/src/domain/props/jwt/create-payload.props.d.ts +9 -0
- package/dist/src/domain/props/jwt/create-payload.props.js +2 -0
- package/dist/src/domain/props/jwt/generate-access-token.props.d.ts +8 -0
- package/dist/src/domain/props/jwt/generate-access-token.props.js +2 -0
- package/dist/src/domain/props/jwt/generate-refresh-token.props.d.ts +8 -0
- package/dist/src/domain/props/jwt/generate-refresh-token.props.js +2 -0
- package/dist/src/domain/props/jwt/generate-token.props.d.ts +10 -0
- package/dist/src/domain/props/jwt/generate-token.props.js +2 -0
- package/dist/src/domain/props/jwt/index.d.ts +5 -0
- package/dist/src/domain/props/jwt/index.js +21 -0
- package/dist/src/domain/props/jwt/jwt-subject.d.ts +7 -0
- package/dist/src/domain/props/jwt/jwt-subject.js +2 -0
- package/dist/src/domain/props/jwt/jwt-user.d.ts +7 -0
- package/dist/src/domain/props/jwt/jwt-user.js +2 -0
- package/dist/src/domain/props/services/generate-access-token.props.d.ts +8 -0
- package/dist/src/domain/props/services/generate-access-token.props.js +2 -0
- package/dist/src/domain/props/services/generate-refresh-token.props.d.ts +8 -0
- package/dist/src/domain/props/services/generate-refresh-token.props.js +2 -0
- package/dist/src/domain/props/services/index.d.ts +2 -0
- package/dist/src/domain/props/services/index.js +18 -0
- package/dist/src/domain/services/index.d.ts +1 -0
- package/dist/src/domain/services/index.js +17 -0
- package/dist/src/domain/services/password-policy.service.d.ts +8 -0
- package/dist/src/domain/services/password-policy.service.js +29 -0
- package/dist/src/domain/services/token.service.port.d.ts +9 -0
- package/dist/src/domain/services/token.service.port.js +2 -0
- package/dist/src/index.d.ts +78 -0
- package/dist/src/index.js +94 -0
- package/dist/src/infrastructure/index.d.ts +5 -0
- package/dist/src/infrastructure/index.js +21 -0
- package/dist/src/infrastructure/jwt/factory/index.d.ts +1 -0
- package/dist/src/infrastructure/jwt/factory/index.js +17 -0
- package/dist/src/infrastructure/jwt/factory/signature-strategy.factory.d.ts +21 -0
- package/dist/src/infrastructure/jwt/factory/signature-strategy.factory.js +61 -0
- package/dist/src/infrastructure/jwt/index.d.ts +3 -0
- package/dist/src/infrastructure/jwt/index.js +19 -0
- package/dist/src/infrastructure/jwt/signature-strategy.factory.d.ts +21 -0
- package/dist/src/infrastructure/jwt/signature-strategy.factory.js +61 -0
- package/dist/src/infrastructure/jwt/strategies/ecdsa-signature-strategy.d.ts +47 -0
- package/dist/src/infrastructure/jwt/strategies/ecdsa-signature-strategy.js +124 -0
- package/dist/src/infrastructure/jwt/strategies/ecdsa-signature.strategy.d.ts +47 -0
- package/dist/src/infrastructure/jwt/strategies/ecdsa-signature.strategy.js +124 -0
- package/dist/src/infrastructure/jwt/strategies/hmac-signature-strategy.d.ts +54 -0
- package/dist/src/infrastructure/jwt/strategies/hmac-signature-strategy.js +129 -0
- package/dist/src/infrastructure/jwt/strategies/hmac-signature.strategy.d.ts +54 -0
- package/dist/src/infrastructure/jwt/strategies/hmac-signature.strategy.js +129 -0
- package/dist/src/infrastructure/jwt/strategies/index.d.ts +3 -0
- package/dist/src/infrastructure/jwt/strategies/index.js +19 -0
- package/dist/src/infrastructure/jwt/strategies/rsa-signature-strategy.d.ts +47 -0
- package/dist/src/infrastructure/jwt/strategies/rsa-signature-strategy.js +124 -0
- package/dist/src/infrastructure/jwt/strategies/rsa-signature.strategy.d.ts +47 -0
- package/dist/src/infrastructure/jwt/strategies/rsa-signature.strategy.js +124 -0
- package/dist/src/infrastructure/jwt/token/actions/jwt-token-generator.d.ts +57 -0
- package/dist/src/infrastructure/jwt/token/actions/jwt-token-generator.js +123 -0
- package/dist/src/infrastructure/jwt/token/actions/jwt-token-verifier.d.ts +59 -0
- package/dist/src/infrastructure/jwt/token/actions/jwt-token-verifier.js +100 -0
- package/dist/src/infrastructure/jwt/token/index.d.ts +5 -0
- package/dist/src/infrastructure/jwt/token/index.js +21 -0
- package/dist/src/infrastructure/jwt/token/jwt-signer.d.ts +33 -0
- package/dist/src/infrastructure/jwt/token/jwt-signer.js +46 -0
- package/dist/src/infrastructure/jwt/token/jwt-token-parser.d.ts +29 -0
- package/dist/src/infrastructure/jwt/token/jwt-token-parser.js +57 -0
- package/dist/src/infrastructure/jwt/token/jwt-token-validator.d.ts +32 -0
- package/dist/src/infrastructure/jwt/token/jwt-token-validator.js +77 -0
- package/dist/src/infrastructure/jwt/token/tools/jwt-signer.d.ts +33 -0
- package/dist/src/infrastructure/jwt/token/tools/jwt-signer.js +46 -0
- package/dist/src/infrastructure/jwt/token/tools/jwt-token-parser.d.ts +30 -0
- package/dist/src/infrastructure/jwt/token/tools/jwt-token-parser.js +57 -0
- package/dist/src/infrastructure/jwt/token/tools/jwt-token-validator.d.ts +32 -0
- package/dist/src/infrastructure/jwt/token/tools/jwt-token-validator.js +77 -0
- package/dist/src/infrastructure/repositories/index.d.ts +1 -0
- package/dist/src/infrastructure/repositories/index.js +17 -0
- package/dist/src/infrastructure/repositories/test/in-memory-credential.repository.d.ts +12 -0
- package/dist/src/infrastructure/repositories/test/in-memory-credential.repository.js +68 -0
- package/dist/src/infrastructure/repositories/test/in-memory-token-session.repository.d.ts +67 -0
- package/dist/src/infrastructure/repositories/test/in-memory-token-session.repository.js +128 -0
- package/dist/src/infrastructure/repositories/test/in-memory-user.repository.d.ts +11 -0
- package/dist/src/infrastructure/repositories/test/in-memory-user.repository.js +49 -0
- package/dist/src/infrastructure/repositories/test/index.d.ts +2 -0
- package/dist/src/infrastructure/repositories/test/index.js +18 -0
- package/dist/src/infrastructure/security/bcrypt-password-hasher.d.ts +6 -0
- package/dist/src/infrastructure/security/bcrypt-password-hasher.js +19 -0
- package/dist/src/infrastructure/security/index.d.ts +1 -0
- package/dist/src/infrastructure/security/index.js +17 -0
- package/dist/src/infrastructure/services/default-token-session.service.d.ts +18 -0
- package/dist/src/infrastructure/services/default-token-session.service.js +88 -0
- package/dist/src/infrastructure/services/index.d.ts +2 -0
- package/dist/src/infrastructure/services/index.js +18 -0
- package/dist/src/infrastructure/services/jwt-token.service.d.ts +15 -0
- package/dist/src/infrastructure/services/jwt-token.service.js +44 -0
- package/dist/src/infrastructure/services/simple-jwt-token.service.d.ts +15 -0
- package/dist/src/infrastructure/services/simple-jwt-token.service.js +46 -0
- package/dist/src/infrastructure/services/token-session.service.d.ts +24 -0
- package/dist/src/infrastructure/services/token-session.service.js +131 -0
- package/dist/src/infrastructure/types/auth-service-container.d.ts +14 -0
- package/dist/src/infrastructure/types/auth-service-container.js +2 -0
- package/dist/src/infrastructure/types/index.d.ts +1 -0
- package/dist/src/infrastructure/types/index.js +17 -0
- package/dist/src/shared/constants/index.d.ts +1 -0
- package/dist/src/shared/constants/index.js +17 -0
- package/dist/src/shared/constants/jwt-algorithms.d.ts +17 -0
- package/dist/src/shared/constants/jwt-algorithms.js +23 -0
- package/dist/src/shared/encoders/base64-url-encoder.d.ts +29 -0
- package/dist/src/shared/encoders/base64-url-encoder.js +45 -0
- package/dist/src/shared/encoders/index.d.ts +1 -0
- package/dist/src/shared/encoders/index.js +17 -0
- package/dist/src/shared/index.d.ts +4 -0
- package/dist/src/shared/index.js +20 -0
- package/dist/src/shared/types/index.d.ts +1 -0
- package/dist/src/shared/types/index.js +17 -0
- package/dist/src/shared/types/jwt.d.ts +25 -0
- package/dist/src/shared/types/jwt.js +2 -0
- package/dist/src/shared/types/jwt.types.d.ts +39 -0
- package/dist/src/shared/types/jwt.types.js +2 -0
- package/dist/src/shared/utils/index.d.ts +1 -0
- package/dist/src/shared/utils/index.js +17 -0
- package/dist/src/shared/utils/time-parser.d.ts +28 -0
- package/dist/src/shared/utils/time-parser.js +76 -0
- package/dist/tests/application/factory/auth-service-factory.spec.d.ts +1 -0
- package/dist/tests/application/factory/auth-service-factory.spec.js +97 -0
- package/dist/tests/application/use-cases/login-with-password.integration.spec.d.ts +1 -0
- package/dist/tests/application/use-cases/login-with-password.integration.spec.js +140 -0
- package/dist/tests/application/use-cases/logout-use-case.spec.d.ts +1 -0
- package/dist/tests/application/use-cases/logout-use-case.spec.js +40 -0
- package/dist/tests/application/use-cases/refresh-token-use-case.spec.d.ts +1 -0
- package/dist/tests/application/use-cases/refresh-token-use-case.spec.js +116 -0
- package/dist/tests/application/use-cases/register-user.usecase.spec.d.ts +1 -0
- package/dist/tests/application/use-cases/register-user.usecase.spec.js +151 -0
- package/dist/tests/domain/entities/credential.spec.d.ts +1 -0
- package/dist/tests/domain/entities/credential.spec.js +93 -0
- package/dist/tests/domain/entities/user.spec.d.ts +1 -0
- package/dist/tests/domain/entities/user.spec.js +93 -0
- package/dist/tests/domain/object-values/email.spec.d.ts +1 -0
- package/dist/tests/domain/object-values/email.spec.js +77 -0
- package/dist/tests/domain/object-values/hashed-password.spec.d.ts +1 -0
- package/dist/tests/domain/object-values/hashed-password.spec.js +54 -0
- package/dist/tests/domain/object-values/id.spec.d.ts +1 -0
- package/dist/tests/domain/object-values/id.spec.js +48 -0
- package/dist/tests/domain/object-values/permission.spec.d.ts +1 -0
- package/dist/tests/domain/object-values/permission.spec.js +75 -0
- package/dist/tests/domain/object-values/role.spec.d.ts +1 -0
- package/dist/tests/domain/object-values/role.spec.js +139 -0
- package/dist/tests/domain/services/default-password-policy.spec.d.ts +1 -0
- package/dist/tests/domain/services/default-password-policy.spec.js +69 -0
- package/dist/tests/doman/entities/credential.spec.d.ts +1 -0
- package/dist/tests/doman/entities/credential.spec.js +93 -0
- package/dist/tests/doman/entities/user.spec.d.ts +1 -0
- package/dist/tests/doman/entities/user.spec.js +93 -0
- package/dist/tests/doman/object-values/email.spec.d.ts +1 -0
- package/dist/tests/doman/object-values/email.spec.js +77 -0
- package/dist/tests/doman/object-values/hashed-password.spec.d.ts +1 -0
- package/dist/tests/doman/object-values/hashed-password.spec.js +54 -0
- package/dist/tests/doman/object-values/id.spec.d.ts +1 -0
- package/dist/tests/doman/object-values/id.spec.js +48 -0
- package/dist/tests/doman/object-values/permission.spec.d.ts +1 -0
- package/dist/tests/doman/object-values/permission.spec.js +75 -0
- package/dist/tests/doman/object-values/role.spec.d.ts +1 -0
- package/dist/tests/doman/object-values/role.spec.js +139 -0
- package/dist/tests/helpers/make-jwt-subject.d.ts +7 -0
- package/dist/tests/helpers/make-jwt-subject.js +16 -0
- package/dist/tests/helpers/make-jwt-user.d.ts +7 -0
- package/dist/tests/helpers/make-jwt-user.js +16 -0
- package/dist/tests/helpers/make-user.d.ts +2 -0
- package/dist/tests/helpers/make-user.js +15 -0
- package/dist/tests/infrastructure/jwt/signature-strategy-factory.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/signature-strategy-factory.spec.js +127 -0
- package/dist/tests/infrastructure/jwt/strategies/ecdsa-signature-strategy.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/strategies/ecdsa-signature-strategy.spec.js +157 -0
- package/dist/tests/infrastructure/jwt/strategies/hmac-signature-strategy.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/strategies/hmac-signature-strategy.spec.js +150 -0
- package/dist/tests/infrastructure/jwt/strategies/rsa-signature-strategy..spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/strategies/rsa-signature-strategy..spec.js +156 -0
- package/dist/tests/infrastructure/jwt/token/actions/jwt-token-generator.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/token/actions/jwt-token-generator.spec.js +179 -0
- package/dist/tests/infrastructure/jwt/token/actions/jwt-token-verifier.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/token/actions/jwt-token-verifier.spec.js +142 -0
- package/dist/tests/infrastructure/jwt/token/jwt-signer.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/token/jwt-signer.spec.js +125 -0
- package/dist/tests/infrastructure/jwt/token/jwt-token-parser.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/token/jwt-token-parser.spec.js +116 -0
- package/dist/tests/infrastructure/jwt/token/jwt-token-validator.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/token/jwt-token-validator.spec.js +88 -0
- package/dist/tests/infrastructure/jwt/token/tools/jwt-signer.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/token/tools/jwt-signer.spec.js +126 -0
- package/dist/tests/infrastructure/jwt/token/tools/jwt-token-parser.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/token/tools/jwt-token-parser.spec.js +116 -0
- package/dist/tests/infrastructure/jwt/token/tools/jwt-token-validator.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/token/tools/jwt-token-validator.spec.js +88 -0
- package/dist/tests/infrastructure/security/security/bcrypt-password-hasher.spec.d.ts +1 -0
- package/dist/tests/infrastructure/security/security/bcrypt-password-hasher.spec.js +37 -0
- package/dist/tests/infrastructure/services/jwt-token-service.spec.d.ts +1 -0
- package/dist/tests/infrastructure/services/jwt-token-service.spec.js +145 -0
- package/dist/tests/infrastructure/services/token-session.service.spec.d.ts +1 -0
- package/dist/tests/infrastructure/services/token-session.service.spec.js +269 -0
- package/dist/tests/shared/constants/jwt-algorithms.spec.d.ts +1 -0
- package/dist/tests/shared/constants/jwt-algorithms.spec.js +27 -0
- package/dist/tests/shared/encoders/base64-url-encoder.spec.d.ts +1 -0
- package/dist/tests/shared/encoders/base64-url-encoder.spec.js +70 -0
- package/dist/tests/shared/utils/time-parser.spec.d.ts +1 -0
- package/dist/tests/shared/utils/time-parser.spec.js +80 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +17 -0
- package/dist/utils/time-parser.d.ts +28 -0
- package/dist/utils/time-parser.js +76 -0
- package/package.json +48 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const errors_1 = require("../../../src/domain/errors");
|
|
4
|
+
const permission_1 = require("../../../src/domain/object-values/permission");
|
|
5
|
+
const role_1 = require("../../../src/domain/object-values/role");
|
|
6
|
+
describe("Role (Value Object)", () => {
|
|
7
|
+
const P = {
|
|
8
|
+
READ_USERS: permission_1.Permission.create("read:users"),
|
|
9
|
+
READ_ANY: permission_1.Permission.create("read:*"),
|
|
10
|
+
WRITE_POSTS: permission_1.Permission.create("write:posts"),
|
|
11
|
+
STAR: permission_1.Permission.create("*"),
|
|
12
|
+
};
|
|
13
|
+
describe("constructor & validRoles", () => {
|
|
14
|
+
it.each([null, undefined])("lanza si role es %p", (input) => {
|
|
15
|
+
expect(() => new role_1.Role(input)).toThrow(new errors_1.InvalidRoleError("Role cannot be null or undefined"));
|
|
16
|
+
});
|
|
17
|
+
it("lanza si role no es string", () => {
|
|
18
|
+
// @ts-expect-error (intencional para probar runtime)
|
|
19
|
+
expect(() => new role_1.Role(123)).toThrow(new errors_1.InvalidRoleError("Role must be a string"));
|
|
20
|
+
});
|
|
21
|
+
it("lanza si role está vacĂo tras trim", () => {
|
|
22
|
+
expect(() => new role_1.Role(" ")).toThrow(new errors_1.InvalidRoleError("Role cannot be empty"));
|
|
23
|
+
});
|
|
24
|
+
it("acepta cualquier role no vacĂo cuando no se provee validRoles", () => {
|
|
25
|
+
const r = new role_1.Role(" Admin ");
|
|
26
|
+
expect(r.toString()).toBe("admin");
|
|
27
|
+
});
|
|
28
|
+
it("valida role contra validRoles (case-insensitive) y lanza si no está incluido", () => {
|
|
29
|
+
expect(() => new role_1.Role("manager", [], ["Admin", "User"])).toThrow(new errors_1.InvalidRoleError("Invalid role: manager. Valid roles are: Admin, User"));
|
|
30
|
+
});
|
|
31
|
+
it("valida role contra validRoles (case-insensitive) y permite si está incluido", () => {
|
|
32
|
+
const r = new role_1.Role("ADMIN", [], ["admin", "user"]);
|
|
33
|
+
expect(r.toString()).toBe("admin");
|
|
34
|
+
});
|
|
35
|
+
it("lanza si algĂşn validRole no es string", () => {
|
|
36
|
+
expect(() => new role_1.Role("admin", [], ["user", null])).toThrow(new errors_1.InvalidRoleError("Valid roles must be strings"));
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
describe("permissions input", () => {
|
|
40
|
+
it("lanza si algĂşn permission no es instancia de Permission", () => {
|
|
41
|
+
expect(() => new role_1.Role("admin", [P.READ_USERS, "write:posts"])).toThrow(new errors_1.InvalidPermissionError("Permissions must be Permission instances"));
|
|
42
|
+
});
|
|
43
|
+
it("almacena permisos normalizados y sin duplicados", () => {
|
|
44
|
+
const r = new role_1.Role("admin", [
|
|
45
|
+
permission_1.Permission.create("READ:USERS"),
|
|
46
|
+
permission_1.Permission.create("read:users"),
|
|
47
|
+
]);
|
|
48
|
+
const { permissions } = r.getValue();
|
|
49
|
+
// Un solo elemento y normalizado
|
|
50
|
+
expect(permissions).toEqual(["read:users"]);
|
|
51
|
+
});
|
|
52
|
+
it("getPermissions devuelve nuevas instancias de Permission", () => {
|
|
53
|
+
const r = new role_1.Role("admin", [P.READ_USERS, P.WRITE_POSTS]);
|
|
54
|
+
const perms = r.getPermissions();
|
|
55
|
+
expect(perms).toHaveLength(2);
|
|
56
|
+
expect(perms[0]).toBeInstanceOf(permission_1.Permission);
|
|
57
|
+
expect(perms.map((p) => p.getValue())).toEqual(expect.arrayContaining(["read:users", "write:posts"]));
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
describe("consultas de permisos", () => {
|
|
61
|
+
it("hasPermission true para match exacto (string y Permission)", () => {
|
|
62
|
+
const r = new role_1.Role("user", [P.READ_USERS]);
|
|
63
|
+
expect(r.hasPermission("read:users")).toBe(true);
|
|
64
|
+
expect(r.hasPermission(permission_1.Permission.create("READ:USERS"))).toBe(true);
|
|
65
|
+
expect(r.hasPermission("read:posts")).toBe(false);
|
|
66
|
+
});
|
|
67
|
+
it("soporta comodĂn total '*'", () => {
|
|
68
|
+
const r = new role_1.Role("user", [P.STAR]);
|
|
69
|
+
expect(r.hasPermission("cualquier:cosa")).toBe(true);
|
|
70
|
+
expect(r.hasPermission("otra")).toBe(true);
|
|
71
|
+
});
|
|
72
|
+
it("soporta prefijo 'read:*'", () => {
|
|
73
|
+
const r = new role_1.Role("user", [P.READ_ANY]);
|
|
74
|
+
expect(r.hasPermission("read:users")).toBe(true);
|
|
75
|
+
expect(r.hasPermission("read:posts")).toBe(true);
|
|
76
|
+
expect(r.hasPermission("write:users")).toBe(false);
|
|
77
|
+
});
|
|
78
|
+
it("hasAnyPermission true si al menos uno coincide", () => {
|
|
79
|
+
const r = new role_1.Role("user", [P.READ_USERS]);
|
|
80
|
+
expect(r.hasAnyPermission(["read:posts", "read:users"])).toBe(true);
|
|
81
|
+
expect(r.hasAnyPermission(["write:posts", "write:users"])).toBe(false);
|
|
82
|
+
});
|
|
83
|
+
it("hasAllPermissions true si todos coinciden", () => {
|
|
84
|
+
const r = new role_1.Role("user", [P.READ_USERS, P.WRITE_POSTS]);
|
|
85
|
+
expect(r.hasAllPermissions(["read:users", "write:posts"])).toBe(true);
|
|
86
|
+
expect(r.hasAllPermissions(["read:users", "write:users"])).toBe(false);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
describe("utilidades y estáticos", () => {
|
|
90
|
+
it("equals compara por nombre normalizado", () => {
|
|
91
|
+
const a = new role_1.Role("ADMIN");
|
|
92
|
+
const b = new role_1.Role("admin");
|
|
93
|
+
const c = new role_1.Role("user");
|
|
94
|
+
expect(a.equals(b)).toBe(true);
|
|
95
|
+
expect(a.equals(c)).toBe(false);
|
|
96
|
+
});
|
|
97
|
+
it("hasRole es case-insensitive", () => {
|
|
98
|
+
const r = new role_1.Role("manager");
|
|
99
|
+
expect(r.hasRole(" MANAGER ")).toBe(true);
|
|
100
|
+
expect(r.hasRole("user")).toBe(false);
|
|
101
|
+
});
|
|
102
|
+
it("toString devuelve el nombre del rol", () => {
|
|
103
|
+
expect(new role_1.Role("Admin").toString()).toBe("admin");
|
|
104
|
+
});
|
|
105
|
+
it("create crea sin validRoles, withValidRoles valida", () => {
|
|
106
|
+
const a = role_1.Role.create("User", [P.READ_USERS]);
|
|
107
|
+
expect(a.getValue()).toEqual({
|
|
108
|
+
role: "user",
|
|
109
|
+
permissions: ["read:users"],
|
|
110
|
+
});
|
|
111
|
+
const b = role_1.Role.withValidRoles("User", [P.READ_USERS], ["admin", "user"]);
|
|
112
|
+
expect(b.getValuePublic()).toEqual({ role: "user" });
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
describe("withPermissions y canPerform", () => {
|
|
116
|
+
it("withPermissions retorna un NUEVO Role sin mutar el original", () => {
|
|
117
|
+
const base = new role_1.Role("user", [P.READ_USERS]);
|
|
118
|
+
const added = base.withPermissions([P.WRITE_POSTS]);
|
|
119
|
+
// original intacto
|
|
120
|
+
expect(base.getValue().permissions).toEqual(["read:users"]);
|
|
121
|
+
// nuevo con ambos
|
|
122
|
+
expect(added.getValue().permissions).toEqual(expect.arrayContaining(["read:users", "write:posts"]));
|
|
123
|
+
// y siguen sin duplicados si se repiten
|
|
124
|
+
const again = added.withPermissions([permission_1.Permission.create("WRITE:POSTS")]);
|
|
125
|
+
expect(again.getValue().permissions).toEqual(expect.arrayContaining(["read:users", "write:posts"]));
|
|
126
|
+
expect(again.getValue().permissions).toHaveLength(2);
|
|
127
|
+
});
|
|
128
|
+
it("canPerform(action) delega a hasPermission con acciĂłn simple", () => {
|
|
129
|
+
const r = new role_1.Role("user", [permission_1.Permission.create("export")]);
|
|
130
|
+
expect(r.canPerform("export")).toBe(true);
|
|
131
|
+
expect(r.canPerform("import")).toBe(false);
|
|
132
|
+
});
|
|
133
|
+
it("canPerform(action, resource) compone 'action:resource'", () => {
|
|
134
|
+
const r = new role_1.Role("user", [permission_1.Permission.create("read:*")]);
|
|
135
|
+
expect(r.canPerform("read", "users")).toBe(true);
|
|
136
|
+
expect(r.canPerform("write", "users")).toBe(false);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { JwtUser } from "src/domain";
|
|
2
|
+
/**
|
|
3
|
+
* Crea un sujeto JWT falso (id, email y roles)
|
|
4
|
+
* usado por JwtTokenGenerator en los tests.
|
|
5
|
+
* No requiere instanciar entidades reales ni VO con validaciones.
|
|
6
|
+
*/
|
|
7
|
+
export declare function makeJwtSubject(overrides?: Partial<JwtUser>): JwtUser;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeJwtSubject = makeJwtSubject;
|
|
4
|
+
/**
|
|
5
|
+
* Crea un sujeto JWT falso (id, email y roles)
|
|
6
|
+
* usado por JwtTokenGenerator en los tests.
|
|
7
|
+
* No requiere instanciar entidades reales ni VO con validaciones.
|
|
8
|
+
*/
|
|
9
|
+
function makeJwtSubject(overrides = {}) {
|
|
10
|
+
return {
|
|
11
|
+
id: "user-123",
|
|
12
|
+
email: "john.doe@example.com",
|
|
13
|
+
roles: [{ role: "ADMIN" }, { role: "USER" }],
|
|
14
|
+
...overrides,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { JwtUser } from "src/domain";
|
|
2
|
+
/**
|
|
3
|
+
* Crea un sujeto JWT falso (id, email y roles)
|
|
4
|
+
* usado por JwtTokenGenerator en los tests.
|
|
5
|
+
* No requiere instanciar entidades reales ni VO con validaciones.
|
|
6
|
+
*/
|
|
7
|
+
export declare function makeJwtSubject(overrides?: Partial<JwtUser>): JwtUser;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeJwtSubject = makeJwtSubject;
|
|
4
|
+
/**
|
|
5
|
+
* Crea un sujeto JWT falso (id, email y roles)
|
|
6
|
+
* usado por JwtTokenGenerator en los tests.
|
|
7
|
+
* No requiere instanciar entidades reales ni VO con validaciones.
|
|
8
|
+
*/
|
|
9
|
+
function makeJwtSubject(overrides = {}) {
|
|
10
|
+
return {
|
|
11
|
+
id: "user-123",
|
|
12
|
+
email: "john.doe@example.com",
|
|
13
|
+
roles: [{ role: "ADMIN" }, { role: "USER" }],
|
|
14
|
+
...overrides,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeUser565456456 = makeUser565456456;
|
|
4
|
+
const domain_1 = require("src/domain");
|
|
5
|
+
function makeUser565456456() {
|
|
6
|
+
return new domain_1.User({
|
|
7
|
+
id: new domain_1.Id("user-123"),
|
|
8
|
+
email: new domain_1.Email("john.doe@example.com"),
|
|
9
|
+
roles: [new domain_1.Role("admin"), new domain_1.Role("user")],
|
|
10
|
+
password: new domain_1.HashedPassword("$2b$10$W6X...cadenaValidaDeBcrypt.../"),
|
|
11
|
+
isActive: true,
|
|
12
|
+
createdAt: new Date(),
|
|
13
|
+
updatedAt: new Date(),
|
|
14
|
+
});
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
// tests/infrastructure/jwt/signature-strategy-factory.spec.ts
|
|
37
|
+
const domain_1 = require("src/domain");
|
|
38
|
+
const shared_1 = require("src/shared");
|
|
39
|
+
// 👇 Mockeamos el módulo ANTES de importar la factory.
|
|
40
|
+
jest.mock("../../../src/infrastructure/jwt/strategies", () => {
|
|
41
|
+
return {
|
|
42
|
+
HmacSignatureStrategy: jest
|
|
43
|
+
.fn()
|
|
44
|
+
.mockImplementation((alg, enc) => ({
|
|
45
|
+
_type: "hmac",
|
|
46
|
+
alg,
|
|
47
|
+
enc,
|
|
48
|
+
})),
|
|
49
|
+
RsaSignatureStrategy: jest
|
|
50
|
+
.fn()
|
|
51
|
+
.mockImplementation((alg, enc) => ({
|
|
52
|
+
_type: "rsa",
|
|
53
|
+
alg,
|
|
54
|
+
enc,
|
|
55
|
+
})),
|
|
56
|
+
EcdsaSignatureStrategy: jest
|
|
57
|
+
.fn()
|
|
58
|
+
.mockImplementation((alg, enc) => ({
|
|
59
|
+
_type: "ecdsa",
|
|
60
|
+
alg,
|
|
61
|
+
enc,
|
|
62
|
+
})),
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
// importamos la factory y el mĂłdulo mockeado
|
|
66
|
+
const strategies = __importStar(require("../../../src/infrastructure/jwt/strategies"));
|
|
67
|
+
const infrastructure_1 = require("src/infrastructure");
|
|
68
|
+
describe("SignatureStrategyFactory", () => {
|
|
69
|
+
let encoder;
|
|
70
|
+
let factory;
|
|
71
|
+
beforeEach(() => {
|
|
72
|
+
jest.clearAllMocks();
|
|
73
|
+
encoder = new shared_1.Base64UrlEncoder();
|
|
74
|
+
factory = new infrastructure_1.SignatureStrategyFactory(encoder);
|
|
75
|
+
});
|
|
76
|
+
it("instancia HmacSignatureStrategy cuando algoritmo es HS*", () => {
|
|
77
|
+
const hsAlg = Object.values(shared_1.algorithms.hmac)[0] ?? "HS256";
|
|
78
|
+
const result = factory.create(hsAlg);
|
|
79
|
+
expect(strategies.HmacSignatureStrategy).toHaveBeenCalledTimes(1);
|
|
80
|
+
expect(strategies.HmacSignatureStrategy).toHaveBeenCalledWith(hsAlg.toUpperCase(), encoder);
|
|
81
|
+
expect(result).toMatchObject({
|
|
82
|
+
_type: "hmac",
|
|
83
|
+
alg: hsAlg.toUpperCase(),
|
|
84
|
+
enc: encoder,
|
|
85
|
+
});
|
|
86
|
+
expect(strategies.RsaSignatureStrategy).not.toHaveBeenCalled();
|
|
87
|
+
expect(strategies.EcdsaSignatureStrategy).not.toHaveBeenCalled();
|
|
88
|
+
});
|
|
89
|
+
it("instancia RsaSignatureStrategy cuando algoritmo es RS*", () => {
|
|
90
|
+
const rsAlg = Object.values(shared_1.algorithms.rsa)[0] ?? "RS256";
|
|
91
|
+
const result = factory.create(rsAlg);
|
|
92
|
+
expect(strategies.RsaSignatureStrategy).toHaveBeenCalledTimes(1);
|
|
93
|
+
expect(strategies.RsaSignatureStrategy).toHaveBeenCalledWith(rsAlg.toUpperCase(), encoder);
|
|
94
|
+
expect(result).toMatchObject({
|
|
95
|
+
_type: "rsa",
|
|
96
|
+
alg: rsAlg.toUpperCase(),
|
|
97
|
+
enc: encoder,
|
|
98
|
+
});
|
|
99
|
+
expect(strategies.HmacSignatureStrategy).not.toHaveBeenCalled();
|
|
100
|
+
expect(strategies.EcdsaSignatureStrategy).not.toHaveBeenCalled();
|
|
101
|
+
});
|
|
102
|
+
it("instancia EcdsaSignatureStrategy cuando algoritmo es ES*", () => {
|
|
103
|
+
const esAlg = Object.values(shared_1.algorithms.ecdsa)[0] ?? "ES256";
|
|
104
|
+
const result = factory.create(esAlg);
|
|
105
|
+
expect(strategies.EcdsaSignatureStrategy).toHaveBeenCalledTimes(1);
|
|
106
|
+
expect(strategies.EcdsaSignatureStrategy).toHaveBeenCalledWith(esAlg.toUpperCase(), encoder);
|
|
107
|
+
expect(result).toMatchObject({
|
|
108
|
+
_type: "ecdsa",
|
|
109
|
+
alg: esAlg.toUpperCase(),
|
|
110
|
+
enc: encoder,
|
|
111
|
+
});
|
|
112
|
+
expect(strategies.HmacSignatureStrategy).not.toHaveBeenCalled();
|
|
113
|
+
expect(strategies.RsaSignatureStrategy).not.toHaveBeenCalled();
|
|
114
|
+
});
|
|
115
|
+
it("es case-insensitive (toUpperCase defensivo)", () => {
|
|
116
|
+
const hsAlg = (Object.values(shared_1.algorithms.hmac)[0] ?? "HS256").toLowerCase();
|
|
117
|
+
factory.create(hsAlg);
|
|
118
|
+
expect(strategies.HmacSignatureStrategy).toHaveBeenCalledWith(hsAlg.toUpperCase(), encoder);
|
|
119
|
+
});
|
|
120
|
+
it("lanza UnsupportedAlgorithmError si no está soportado", () => {
|
|
121
|
+
const unsupported = "PS256";
|
|
122
|
+
expect(() => factory.create(unsupported)).toThrow(domain_1.UnsupportedAlgorithmError);
|
|
123
|
+
expect(strategies.HmacSignatureStrategy).not.toHaveBeenCalled();
|
|
124
|
+
expect(strategies.RsaSignatureStrategy).not.toHaveBeenCalled();
|
|
125
|
+
expect(strategies.EcdsaSignatureStrategy).not.toHaveBeenCalled();
|
|
126
|
+
});
|
|
127
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// tests/infrastructure/jwt/strategies/EcdsaSignatureStrategy.spec.ts
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
const crypto = __importStar(require("crypto"));
|
|
38
|
+
const strategies_1 = require("src/infrastructure/jwt/strategies");
|
|
39
|
+
const shared_1 = require("src/shared");
|
|
40
|
+
describe("EcdsaSignatureStrategy", () => {
|
|
41
|
+
// FunciĂłn auxiliar para generar par de claves ECDSA
|
|
42
|
+
const makeKeys = (curve) => crypto.generateKeyPairSync("ec", {
|
|
43
|
+
namedCurve: curve,
|
|
44
|
+
publicKeyEncoding: { type: "spki", format: "pem" },
|
|
45
|
+
privateKeyEncoding: { type: "pkcs8", format: "pem" },
|
|
46
|
+
});
|
|
47
|
+
// Datos base para firmar
|
|
48
|
+
const baseData = "header.payload";
|
|
49
|
+
// Vectores de prueba para cada algoritmo ECDSA
|
|
50
|
+
const vectors = [
|
|
51
|
+
{ alg: shared_1.algorithms.ecdsa.ES256, curve: "P-256" },
|
|
52
|
+
{ alg: shared_1.algorithms.ecdsa.ES384, curve: "P-384" },
|
|
53
|
+
{ alg: shared_1.algorithms.ecdsa.ES512, curve: "P-521" },
|
|
54
|
+
];
|
|
55
|
+
// Casos positivos
|
|
56
|
+
it.each(vectors)("sign/verify OK para %s", ({ alg, curve }) => {
|
|
57
|
+
// Genera par de claves
|
|
58
|
+
const { publicKey, privateKey } = makeKeys(curve);
|
|
59
|
+
// Crea la estrategia
|
|
60
|
+
const encoder = new shared_1.Base64UrlEncoder();
|
|
61
|
+
// Crea la estrategia
|
|
62
|
+
const strat = new strategies_1.EcdsaSignatureStrategy(alg, encoder);
|
|
63
|
+
// Firma
|
|
64
|
+
const sig = strat.sign(baseData, privateKey);
|
|
65
|
+
// Debe ser Base64URL (sin +, /, =)
|
|
66
|
+
expect(sig).toMatch(/^[A-Za-z0-9\-_]+$/);
|
|
67
|
+
// verify OK con los mismos datos/clave
|
|
68
|
+
expect(strat.verify(baseData, sig, publicKey)).toBe(true);
|
|
69
|
+
});
|
|
70
|
+
// Casos negativos
|
|
71
|
+
it.each(vectors)("verify=false si los datos se alteran (%s)", ({ alg, curve }) => {
|
|
72
|
+
// Genera par de claves
|
|
73
|
+
const { publicKey, privateKey } = makeKeys(curve);
|
|
74
|
+
// Crea la estrategia
|
|
75
|
+
const encoder = new shared_1.Base64UrlEncoder();
|
|
76
|
+
// Crea la estrategia
|
|
77
|
+
const strat = new strategies_1.EcdsaSignatureStrategy(alg, encoder);
|
|
78
|
+
// Firma
|
|
79
|
+
const sig = strat.sign(baseData, privateKey);
|
|
80
|
+
// verify debe fallar si se alteran los datos
|
|
81
|
+
expect(strat.verify(baseData + ".tampered", sig, publicKey)).toBe(false);
|
|
82
|
+
});
|
|
83
|
+
// Casos negativos - firma alterada
|
|
84
|
+
it.each(vectors)("verify=false si la firma se altera (%s)", ({ alg, curve }) => {
|
|
85
|
+
// Genera par de claves
|
|
86
|
+
const { publicKey, privateKey } = makeKeys(curve);
|
|
87
|
+
// Crea la estrategia
|
|
88
|
+
const encoder = new shared_1.Base64UrlEncoder();
|
|
89
|
+
// Crea la estrategia
|
|
90
|
+
const strat = new strategies_1.EcdsaSignatureStrategy(alg, encoder);
|
|
91
|
+
// Firma
|
|
92
|
+
const sig = strat.sign(baseData, privateKey);
|
|
93
|
+
// Decodificamos a base64 estándar y luego a bytes
|
|
94
|
+
const stdB64 = encoder.decode(sig);
|
|
95
|
+
const buf = Buffer.from(stdB64, "base64");
|
|
96
|
+
// Flip de un byte en el medio (afecta r/s con alta probabilidad)
|
|
97
|
+
const i = Math.floor(buf.length / 2);
|
|
98
|
+
buf[i] ^= 0x01;
|
|
99
|
+
// Re-encode a base64url para pasar por la API pĂşblica de la estrategia
|
|
100
|
+
const tampered = encoder.encode(Buffer.from(buf).toString("base64"));
|
|
101
|
+
expect(strat.verify(baseData, tampered, publicKey)).toBe(false);
|
|
102
|
+
});
|
|
103
|
+
// Pruebas adicionales
|
|
104
|
+
it("getSupportedAlgorithm() devuelve el algoritmo configurado", () => {
|
|
105
|
+
// Crea la estrategia
|
|
106
|
+
const encoder = new shared_1.Base64UrlEncoder();
|
|
107
|
+
// Crea la estrategia
|
|
108
|
+
const strat = new strategies_1.EcdsaSignatureStrategy(shared_1.algorithms.ecdsa.ES256, encoder);
|
|
109
|
+
// Debe devolver el algoritmo configurado
|
|
110
|
+
expect(strat.getSupportedAlgorithm()).toBe("ES256");
|
|
111
|
+
});
|
|
112
|
+
// Casos de error - algoritmo no soportado
|
|
113
|
+
it("sign lanza y verify devuelve false para algoritmo no soportado", () => {
|
|
114
|
+
// Crea la estrategia con un algoritmo inválido
|
|
115
|
+
const badAlg = "ES999";
|
|
116
|
+
// Crea la estrategia
|
|
117
|
+
const encoder = new shared_1.Base64UrlEncoder();
|
|
118
|
+
// Crea la estrategia
|
|
119
|
+
const strat = new strategies_1.EcdsaSignatureStrategy(badAlg, encoder);
|
|
120
|
+
// Genera par de claves válidas
|
|
121
|
+
const { publicKey, privateKey } = makeKeys("P-256");
|
|
122
|
+
// sign debe lanzar error
|
|
123
|
+
expect(() => strat.sign(baseData, privateKey)).toThrow(/Unsupported ECDSA algorithm/i);
|
|
124
|
+
// verify debe devolver false
|
|
125
|
+
expect(strat.verify(baseData, "abc", publicKey)).toBe(false);
|
|
126
|
+
});
|
|
127
|
+
// Prueba que se usa el encoder correctamente
|
|
128
|
+
it("usa el encoder para encode (sign) y decode (verify)", () => {
|
|
129
|
+
// Mocks del encoder
|
|
130
|
+
const encoder = {
|
|
131
|
+
encode: jest.fn((b64) => b64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "")),
|
|
132
|
+
decode: jest.fn((b64url) => {
|
|
133
|
+
const pad = b64url.length % 4;
|
|
134
|
+
let std = b64url.replace(/-/g, "+").replace(/_/g, "/");
|
|
135
|
+
if (pad)
|
|
136
|
+
std += "=".repeat(4 - pad);
|
|
137
|
+
return std;
|
|
138
|
+
}),
|
|
139
|
+
};
|
|
140
|
+
// Genera par de claves válidas
|
|
141
|
+
const { publicKey, privateKey } = makeKeys("P-256");
|
|
142
|
+
// Crea la estrategia
|
|
143
|
+
const strat = new strategies_1.EcdsaSignatureStrategy(shared_1.algorithms.ecdsa.ES256, encoder);
|
|
144
|
+
// Firma
|
|
145
|
+
const sig = strat.sign(baseData, privateKey);
|
|
146
|
+
// Verifica que se llamĂł al encoder
|
|
147
|
+
expect(encoder.encode).toHaveBeenCalledTimes(1);
|
|
148
|
+
// El resultado debe ser string
|
|
149
|
+
expect(typeof sig).toBe("string");
|
|
150
|
+
// Verifica
|
|
151
|
+
const ok = strat.verify(baseData, sig, publicKey);
|
|
152
|
+
// Verifica que se llamĂł al decoder
|
|
153
|
+
expect(encoder.decode).toHaveBeenCalledTimes(1);
|
|
154
|
+
// El resultado debe ser true
|
|
155
|
+
expect(ok).toBe(true);
|
|
156
|
+
});
|
|
157
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const crypto = __importStar(require("crypto"));
|
|
37
|
+
const infrastructure_1 = require("src/infrastructure");
|
|
38
|
+
const shared_1 = require("src/shared");
|
|
39
|
+
describe("HmacSignatureStrategy", () => {
|
|
40
|
+
// 🔑 Clave simétrica compartida
|
|
41
|
+
const makeSecret = (length = 32) => crypto.randomBytes(length).toString("base64url");
|
|
42
|
+
// Datos base para firmar
|
|
43
|
+
const baseData = "header.payload";
|
|
44
|
+
// Vectores de prueba para cada algoritmo HMAC
|
|
45
|
+
const vectors = [
|
|
46
|
+
{ alg: shared_1.algorithms.hmac.HS256, hash: "sha256" },
|
|
47
|
+
{ alg: shared_1.algorithms.hmac.HS384, hash: "sha384" },
|
|
48
|
+
{ alg: shared_1.algorithms.hmac.HS512, hash: "sha512" },
|
|
49
|
+
];
|
|
50
|
+
// Casos positivos
|
|
51
|
+
it.each(vectors)("firma y verifica correctamente con %s", ({ alg }) => {
|
|
52
|
+
// Genera clave secreta
|
|
53
|
+
const secret = makeSecret();
|
|
54
|
+
// Crea la estrategia
|
|
55
|
+
const encoder = new shared_1.Base64UrlEncoder();
|
|
56
|
+
const strategy = new infrastructure_1.HmacSignatureStrategy(alg, encoder);
|
|
57
|
+
// Firma
|
|
58
|
+
const sig = strategy.sign(baseData, secret);
|
|
59
|
+
// Debe ser Base64URL (sin +, /, =)
|
|
60
|
+
const valid = strategy.verify(baseData, sig, secret);
|
|
61
|
+
// Debe ser válido
|
|
62
|
+
expect(valid).toBe(true);
|
|
63
|
+
});
|
|
64
|
+
// Casos negativos
|
|
65
|
+
it.each(vectors)("verify=false si los datos se alteran (%s)", ({ alg }) => {
|
|
66
|
+
// Genera clave secreta
|
|
67
|
+
const secret = makeSecret();
|
|
68
|
+
// Crea la estrategia
|
|
69
|
+
const encoder = new shared_1.Base64UrlEncoder();
|
|
70
|
+
const strategy = new infrastructure_1.HmacSignatureStrategy(alg, encoder);
|
|
71
|
+
// Firma
|
|
72
|
+
const sig = strategy.sign(baseData, secret);
|
|
73
|
+
// verify debe fallar si se alteran los datos
|
|
74
|
+
expect(strategy.verify(baseData + ".tampered", sig, secret)).toBe(false);
|
|
75
|
+
});
|
|
76
|
+
// Casos negativos - firma alterada
|
|
77
|
+
it.each(vectors)("verify=false si la firma se altera (%s)", ({ alg }) => {
|
|
78
|
+
// Genera clave secreta
|
|
79
|
+
const secret = makeSecret();
|
|
80
|
+
// Crea la estrategia
|
|
81
|
+
const encoder = new shared_1.Base64UrlEncoder();
|
|
82
|
+
const strategy = new infrastructure_1.HmacSignatureStrategy(alg, encoder);
|
|
83
|
+
// Firma
|
|
84
|
+
const sig = strategy.sign(baseData, secret);
|
|
85
|
+
// Decodificamos a base64 estándar y luego a bytes
|
|
86
|
+
const stdB64 = encoder.decode(sig);
|
|
87
|
+
const buf = Buffer.from(stdB64, "base64");
|
|
88
|
+
// Flip de un byte en el medio (afecta r/s con alta probabilidad)
|
|
89
|
+
const i = Math.floor(buf.length / 2);
|
|
90
|
+
buf[i] ^= 0x01;
|
|
91
|
+
// Re-encode a base64url para pasar por la API pĂşblica de la estrategia
|
|
92
|
+
const tampered = encoder.encode(Buffer.from(buf).toString("base64"));
|
|
93
|
+
expect(strategy.verify(baseData, tampered, secret)).toBe(false);
|
|
94
|
+
});
|
|
95
|
+
// Pruebas adicionales
|
|
96
|
+
it("getSupportedAlgorithm() devuelve el algoritmo configurado", () => {
|
|
97
|
+
// Crea la estrategia
|
|
98
|
+
const encoder = new shared_1.Base64UrlEncoder();
|
|
99
|
+
// Crea la estrategia
|
|
100
|
+
const strat = new infrastructure_1.HmacSignatureStrategy(shared_1.algorithms.hmac.HS256, encoder);
|
|
101
|
+
// Debe devolver el algoritmo configurado
|
|
102
|
+
expect(strat.getSupportedAlgorithm()).toBe("HS256");
|
|
103
|
+
});
|
|
104
|
+
// Casos de error - algoritmo no soportado
|
|
105
|
+
it("sign lanza y verify devuelve false para algoritmo no soportado", () => {
|
|
106
|
+
// Crea la estrategia con un algoritmo inválido
|
|
107
|
+
const badAlg = "HS999";
|
|
108
|
+
// Crea la estrategia
|
|
109
|
+
const encoder = new shared_1.Base64UrlEncoder();
|
|
110
|
+
// Crea la estrategia
|
|
111
|
+
const strat = new infrastructure_1.HmacSignatureStrategy(badAlg, encoder);
|
|
112
|
+
// Genera par de claves válidas
|
|
113
|
+
const secret = makeSecret();
|
|
114
|
+
// sign debe lanzar error
|
|
115
|
+
expect(() => strat.sign(baseData, secret)).toThrow(/Unsupported HMAC algorithm/i);
|
|
116
|
+
// verify debe devolver false
|
|
117
|
+
expect(strat.verify(baseData, "abc", secret)).toBe(false);
|
|
118
|
+
});
|
|
119
|
+
// Prueba que se usa el encoder correctamente
|
|
120
|
+
it("usa el encoder para encode (sign) y decode (verify)", () => {
|
|
121
|
+
// Mocks del encoder
|
|
122
|
+
const encoder = {
|
|
123
|
+
encode: jest.fn((b64) => b64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "")),
|
|
124
|
+
decode: jest.fn((b64url) => {
|
|
125
|
+
const pad = b64url.length % 4;
|
|
126
|
+
let std = b64url.replace(/-/g, "+").replace(/_/g, "/");
|
|
127
|
+
if (pad)
|
|
128
|
+
std += "=".repeat(4 - pad);
|
|
129
|
+
return std;
|
|
130
|
+
}),
|
|
131
|
+
};
|
|
132
|
+
// Genera clave secreta
|
|
133
|
+
const secret = makeSecret();
|
|
134
|
+
// Crea la estrategia
|
|
135
|
+
// Crea la estrategia
|
|
136
|
+
const strat = new infrastructure_1.HmacSignatureStrategy(shared_1.algorithms.hmac.HS256, encoder);
|
|
137
|
+
// Firma
|
|
138
|
+
const sig = strat.sign(baseData, secret);
|
|
139
|
+
// Verifica que se llamĂł al encoder
|
|
140
|
+
expect(encoder.encode).toHaveBeenCalledTimes(1);
|
|
141
|
+
// El resultado debe ser string
|
|
142
|
+
expect(typeof sig).toBe("string");
|
|
143
|
+
// Verifica
|
|
144
|
+
const ok = strat.verify(baseData, sig, secret);
|
|
145
|
+
// Verifica que se no se llamĂł al decoder (no lo necesita HMAC)
|
|
146
|
+
expect(encoder.decode).toHaveBeenCalledTimes(0);
|
|
147
|
+
// El resultado debe ser true
|
|
148
|
+
expect(ok).toBe(true);
|
|
149
|
+
});
|
|
150
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|