@jmlq/auth 0.0.1-alpha.1 → 0.0.1-alpha.3
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 +259 -306
- package/dist/application/dtos/index.d.ts +3 -0
- package/dist/application/dtos/index.js +19 -0
- package/dist/application/dtos/request/index.d.ts +4 -0
- package/dist/{src/application/dtos → application/dtos/request}/index.js +4 -4
- package/dist/{src/application/dtos/login.dto.d.ts → application/dtos/request/login.request.d.ts} +0 -4
- package/dist/application/dtos/request/logout.request.d.ts +3 -0
- package/dist/application/dtos/request/refresh-token.request.d.ts +3 -0
- package/dist/application/dtos/request/register-user.request.d.ts +6 -0
- package/dist/application/dtos/response/index.d.ts +4 -0
- package/dist/application/dtos/response/index.js +20 -0
- package/dist/application/dtos/response/login.response.d.ts +4 -0
- package/dist/{src/application/dtos/logout.dto.d.ts → application/dtos/response/logout.response.d.ts} +0 -3
- package/dist/{src/application/dtos/refresh-token.dto.d.ts → application/dtos/response/refresh-token.response.d.ts} +0 -3
- package/dist/application/dtos/response/register-user.response.d.ts +7 -0
- package/dist/application/dtos/type/index.d.ts +1 -0
- package/dist/{src/shared/constants → application/dtos/type}/index.js +1 -1
- package/dist/application/dtos/type/user-role.type.d.ts +4 -0
- package/dist/application/factories/auth-service.factory.d.ts +11 -0
- package/dist/application/factories/auth-service.factory.js +40 -0
- package/dist/{src/application → application}/index.d.ts +1 -0
- package/dist/{src/application → application}/index.js +1 -0
- package/dist/application/types/auth-service-factory-options.type.d.ts +5 -0
- package/dist/application/types/index.d.ts +1 -0
- package/dist/{src/infrastructure/jwt/factory → application/types}/index.js +1 -1
- package/dist/{src/application → application}/use-cases/login-with-password.use-case.d.ts +2 -2
- package/dist/{src/application → application}/use-cases/login-with-password.use-case.js +6 -5
- package/dist/{src/application → application}/use-cases/logout.use-case.d.ts +2 -2
- package/dist/{src/application → application}/use-cases/logout.use-case.js +2 -2
- package/dist/{src/application → application}/use-cases/refresh-token.use-case.d.ts +2 -2
- package/dist/{src/application → application}/use-cases/refresh-token.use-case.js +2 -2
- package/dist/application/use-cases/register-user.use-case.d.ts +12 -0
- package/dist/{src/application → application}/use-cases/register-user.use-case.js +27 -1
- package/dist/{src/domain → domain}/errors/auth.errors.d.ts +1 -14
- package/dist/{src/domain → domain}/errors/auth.errors.js +1 -15
- package/dist/{src/domain → domain}/index.d.ts +0 -1
- package/dist/{src/domain → domain}/index.js +0 -1
- package/dist/domain/ports/auth/index.d.ts +2 -0
- package/dist/domain/ports/auth/index.js +18 -0
- package/dist/{src/domain/ports/auth/password-hasher.d.ts → domain/ports/auth/password-hasher.port.d.ts} +1 -1
- package/dist/{src/domain → domain}/ports/auth/password-policy.port.d.ts +1 -1
- package/dist/domain/ports/index.d.ts +4 -0
- package/dist/{src/infrastructure/jwt → domain/ports}/index.js +3 -2
- package/dist/domain/ports/jwt/index.d.ts +1 -0
- package/dist/{src/shared/types → domain/ports/jwt}/index.js +1 -1
- package/dist/domain/ports/jwt/payload/index.d.ts +1 -0
- package/dist/domain/ports/jwt/payload/index.js +17 -0
- package/dist/{src/domain → domain}/ports/repository/credential.repository.d.ts +1 -1
- package/dist/{src/domain → domain}/ports/repository/index.d.ts +1 -1
- package/dist/{src/domain → domain}/ports/repository/index.js +1 -1
- package/dist/{src/domain/ports/repository/user.repository.d.ts → domain/ports/repository/user-repository.port.d.ts} +1 -1
- package/dist/domain/ports/token/index.d.ts +2 -0
- package/dist/domain/ports/token/index.js +18 -0
- package/dist/{src/domain → domain}/ports/token/token-session.port.d.ts +2 -2
- package/dist/{src/domain → domain}/ports/token/token.service.port.d.ts +2 -2
- package/dist/{src/domain → domain}/props/jwt/generate-access-token.props.d.ts +0 -2
- package/dist/{src/domain → domain}/props/jwt/generate-refresh-token.props.d.ts +0 -2
- package/dist/{src/domain/props/services → domain/props/jwt}/index.d.ts +1 -0
- package/dist/{src/domain/props/services → domain/props/jwt}/index.js +1 -0
- package/dist/{src/domain → domain}/services/password-policy.service.d.ts +2 -2
- package/dist/{src/infrastructure/repositories/test → in-memory}/in-memory-credential.repository.d.ts +2 -2
- package/dist/{src/infrastructure/repositories/test → in-memory}/in-memory-credential.repository.js +12 -2
- package/dist/{src/infrastructure/repositories/test → in-memory}/in-memory-user.repository.d.ts +2 -2
- package/dist/index.d.ts +5 -1
- package/dist/index.js +13 -1
- package/dist/infrastructure/index.js +1 -0
- package/dist/{src/infrastructure → infrastructure}/security/bcrypt-password-hasher.d.ts +7 -2
- package/dist/{src/infrastructure → infrastructure}/security/bcrypt-password-hasher.js +7 -2
- package/dist/{src/infrastructure → infrastructure}/services/index.d.ts +0 -1
- package/dist/{src/infrastructure → infrastructure}/services/index.js +0 -1
- package/dist/infrastructure/services/token-session.service.d.ts +22 -0
- package/dist/{src/infrastructure/services/default-token-session.service.js → infrastructure/services/token-session.service.js} +30 -31
- package/dist/infrastructure/types/auth-service-container.d.ts +14 -0
- package/dist/shared/index.d.ts +1 -0
- package/dist/{src/infrastructure/repositories → shared}/index.js +1 -1
- package/package.json +5 -8
- package/dist/examples/bcrypt-password-hasher.example.d.ts +0 -3
- package/dist/examples/bcrypt-password-hasher.example.js +0 -78
- package/dist/examples/entity-object.example.d.ts +0 -39
- package/dist/examples/entity-object.example.js +0 -411
- package/dist/examples/factory-auth-service-example.d.ts +0 -3
- package/dist/examples/factory-auth-service-example.js +0 -84
- package/dist/examples/index.example.d.ts +0 -12
- package/dist/examples/index.example.js +0 -171
- package/dist/examples/jwt-algoritm.example.d.ts +0 -47
- package/dist/examples/jwt-algoritm.example.js +0 -447
- package/dist/examples/jwt-token-generator.example.d.ts +0 -6
- package/dist/examples/jwt-token-generator.example.js +0 -49
- package/dist/examples/jwt-verifier.example.d.ts +0 -3
- package/dist/examples/jwt-verifier.example.js +0 -80
- package/dist/examples/password-policy.example.d.ts +0 -7
- package/dist/examples/password-policy.example.js +0 -57
- package/dist/examples/service-jwt-token.example.d.ts +0 -3
- package/dist/examples/service-jwt-token.example.js +0 -154
- package/dist/examples/service-token-session.example.d.ts +0 -3
- package/dist/examples/service-token-session.example.js +0 -139
- package/dist/examples/use-case-login-with-password.example.d.ts +0 -6
- package/dist/examples/use-case-login-with-password.example.js +0 -105
- package/dist/examples/use-case-logout.example.d.ts +0 -7
- package/dist/examples/use-case-logout.example.js +0 -134
- package/dist/examples/use-case-refresh-token.example.d.ts +0 -11
- package/dist/examples/use-case-refresh-token.example.js +0 -164
- package/dist/examples/use-case-register-user.example.d.ts +0 -9
- package/dist/examples/use-case-register-user.example.js +0 -110
- package/dist/src/application/dtos/index.d.ts +0 -4
- package/dist/src/application/dtos/register-user.dto.d.ts +0 -16
- package/dist/src/application/factories/auth-service.factory.d.ts +0 -5
- package/dist/src/application/factories/auth-service.factory.js +0 -51
- package/dist/src/application/use-cases/register-user.use-case.d.ts +0 -10
- package/dist/src/domain/errors/auth-domain-error.d.ts +0 -82
- package/dist/src/domain/errors/auth-domain-error.js +0 -112
- package/dist/src/domain/ports/auth/password-policy-config.port.js +0 -10
- package/dist/src/domain/ports/config/auth-config.port.d.ts +0 -19
- package/dist/src/domain/ports/config/auth-config.port.js +0 -3
- package/dist/src/domain/ports/index.d.ts +0 -9
- package/dist/src/domain/ports/index.js +0 -25
- package/dist/src/domain/ports/jwt/factory/signature-strategy-factory.port.d.ts +0 -14
- package/dist/src/domain/ports/jwt/signature-strategy-factory.port.d.ts +0 -14
- package/dist/src/domain/ports/jwt/signature-strategy.d.ts +0 -30
- package/dist/src/domain/ports/jwt/signature-strategy.js +0 -4
- package/dist/src/domain/ports/jwt/signature-strategy.port.d.ts +0 -31
- package/dist/src/domain/ports/jwt/signature-strategy.port.js +0 -4
- package/dist/src/domain/ports/jwt/strategy/signature-strategy.port.d.ts +0 -31
- package/dist/src/domain/ports/jwt/strategy/signature-strategy.port.js +0 -4
- package/dist/src/domain/props/create-payload-props.port.d.ts +0 -0
- package/dist/src/domain/props/create-payload-props.port.js +0 -8
- package/dist/src/domain/props/jwt/create-payload.props.d.ts +0 -9
- package/dist/src/domain/props/jwt/generate-token.props.d.ts +0 -10
- package/dist/src/domain/props/jwt/generate-token.props.js +0 -2
- package/dist/src/domain/props/jwt/index.d.ts +0 -5
- package/dist/src/domain/props/jwt/index.js +0 -21
- package/dist/src/domain/props/jwt/jwt-subject.d.ts +0 -7
- package/dist/src/domain/props/jwt/jwt-subject.js +0 -2
- package/dist/src/domain/props/services/generate-access-token.props.d.ts +0 -8
- package/dist/src/domain/props/services/generate-refresh-token.props.d.ts +0 -8
- package/dist/src/domain/services/token.service.port.d.ts +0 -9
- package/dist/src/index.d.ts +0 -78
- package/dist/src/index.js +0 -94
- package/dist/src/infrastructure/index.d.ts +0 -5
- package/dist/src/infrastructure/index.js +0 -21
- package/dist/src/infrastructure/jwt/factory/index.d.ts +0 -1
- package/dist/src/infrastructure/jwt/factory/signature-strategy.factory.d.ts +0 -21
- package/dist/src/infrastructure/jwt/factory/signature-strategy.factory.js +0 -61
- package/dist/src/infrastructure/jwt/index.d.ts +0 -3
- package/dist/src/infrastructure/jwt/signature-strategy.factory.d.ts +0 -21
- package/dist/src/infrastructure/jwt/signature-strategy.factory.js +0 -61
- package/dist/src/infrastructure/jwt/strategies/ecdsa-signature-strategy.d.ts +0 -47
- package/dist/src/infrastructure/jwt/strategies/ecdsa-signature-strategy.js +0 -124
- package/dist/src/infrastructure/jwt/strategies/ecdsa-signature.strategy.d.ts +0 -47
- package/dist/src/infrastructure/jwt/strategies/ecdsa-signature.strategy.js +0 -124
- package/dist/src/infrastructure/jwt/strategies/hmac-signature-strategy.d.ts +0 -54
- package/dist/src/infrastructure/jwt/strategies/hmac-signature-strategy.js +0 -129
- package/dist/src/infrastructure/jwt/strategies/hmac-signature.strategy.d.ts +0 -54
- package/dist/src/infrastructure/jwt/strategies/hmac-signature.strategy.js +0 -129
- package/dist/src/infrastructure/jwt/strategies/index.d.ts +0 -3
- package/dist/src/infrastructure/jwt/strategies/index.js +0 -19
- package/dist/src/infrastructure/jwt/strategies/rsa-signature-strategy.d.ts +0 -47
- package/dist/src/infrastructure/jwt/strategies/rsa-signature-strategy.js +0 -124
- package/dist/src/infrastructure/jwt/strategies/rsa-signature.strategy.d.ts +0 -47
- package/dist/src/infrastructure/jwt/strategies/rsa-signature.strategy.js +0 -124
- package/dist/src/infrastructure/jwt/token/actions/jwt-token-generator.d.ts +0 -57
- package/dist/src/infrastructure/jwt/token/actions/jwt-token-generator.js +0 -123
- package/dist/src/infrastructure/jwt/token/actions/jwt-token-verifier.d.ts +0 -59
- package/dist/src/infrastructure/jwt/token/actions/jwt-token-verifier.js +0 -100
- package/dist/src/infrastructure/jwt/token/index.d.ts +0 -5
- package/dist/src/infrastructure/jwt/token/index.js +0 -21
- package/dist/src/infrastructure/jwt/token/jwt-signer.d.ts +0 -33
- package/dist/src/infrastructure/jwt/token/jwt-signer.js +0 -46
- package/dist/src/infrastructure/jwt/token/jwt-token-parser.d.ts +0 -29
- package/dist/src/infrastructure/jwt/token/jwt-token-parser.js +0 -57
- package/dist/src/infrastructure/jwt/token/jwt-token-validator.d.ts +0 -32
- package/dist/src/infrastructure/jwt/token/jwt-token-validator.js +0 -77
- package/dist/src/infrastructure/jwt/token/tools/jwt-signer.d.ts +0 -33
- package/dist/src/infrastructure/jwt/token/tools/jwt-signer.js +0 -46
- package/dist/src/infrastructure/jwt/token/tools/jwt-token-parser.d.ts +0 -30
- package/dist/src/infrastructure/jwt/token/tools/jwt-token-parser.js +0 -57
- package/dist/src/infrastructure/jwt/token/tools/jwt-token-validator.d.ts +0 -32
- package/dist/src/infrastructure/jwt/token/tools/jwt-token-validator.js +0 -77
- package/dist/src/infrastructure/repositories/index.d.ts +0 -1
- package/dist/src/infrastructure/repositories/test/in-memory-token-session.repository.d.ts +0 -67
- package/dist/src/infrastructure/repositories/test/in-memory-token-session.repository.js +0 -128
- package/dist/src/infrastructure/services/default-token-session.service.d.ts +0 -18
- package/dist/src/infrastructure/services/jwt-token.service.d.ts +0 -15
- package/dist/src/infrastructure/services/jwt-token.service.js +0 -44
- package/dist/src/infrastructure/services/simple-jwt-token.service.d.ts +0 -15
- package/dist/src/infrastructure/services/simple-jwt-token.service.js +0 -46
- package/dist/src/infrastructure/services/token-session.service.d.ts +0 -24
- package/dist/src/infrastructure/services/token-session.service.js +0 -131
- package/dist/src/infrastructure/types/auth-service-container.d.ts +0 -14
- package/dist/src/shared/constants/index.d.ts +0 -1
- package/dist/src/shared/constants/jwt-algorithms.d.ts +0 -17
- package/dist/src/shared/constants/jwt-algorithms.js +0 -23
- package/dist/src/shared/encoders/base64-url-encoder.d.ts +0 -29
- package/dist/src/shared/encoders/base64-url-encoder.js +0 -45
- package/dist/src/shared/encoders/index.d.ts +0 -1
- package/dist/src/shared/encoders/index.js +0 -17
- package/dist/src/shared/index.d.ts +0 -4
- package/dist/src/shared/index.js +0 -20
- package/dist/src/shared/types/index.d.ts +0 -1
- package/dist/src/shared/types/jwt.d.ts +0 -25
- package/dist/src/shared/types/jwt.js +0 -2
- package/dist/src/shared/types/jwt.types.d.ts +0 -39
- package/dist/src/shared/types/jwt.types.js +0 -2
- package/dist/tests/application/factory/auth-service-factory.spec.d.ts +0 -1
- package/dist/tests/application/factory/auth-service-factory.spec.js +0 -97
- package/dist/tests/application/use-cases/login-with-password.integration.spec.d.ts +0 -1
- package/dist/tests/application/use-cases/login-with-password.integration.spec.js +0 -140
- package/dist/tests/application/use-cases/logout-use-case.spec.d.ts +0 -1
- package/dist/tests/application/use-cases/logout-use-case.spec.js +0 -40
- package/dist/tests/application/use-cases/refresh-token-use-case.spec.d.ts +0 -1
- package/dist/tests/application/use-cases/refresh-token-use-case.spec.js +0 -116
- package/dist/tests/application/use-cases/register-user.usecase.spec.d.ts +0 -1
- package/dist/tests/application/use-cases/register-user.usecase.spec.js +0 -151
- package/dist/tests/domain/entities/credential.spec.d.ts +0 -1
- package/dist/tests/domain/entities/credential.spec.js +0 -93
- package/dist/tests/domain/entities/user.spec.d.ts +0 -1
- package/dist/tests/domain/entities/user.spec.js +0 -93
- package/dist/tests/domain/object-values/email.spec.d.ts +0 -1
- package/dist/tests/domain/object-values/email.spec.js +0 -77
- package/dist/tests/domain/object-values/hashed-password.spec.d.ts +0 -1
- package/dist/tests/domain/object-values/hashed-password.spec.js +0 -54
- package/dist/tests/domain/object-values/id.spec.d.ts +0 -1
- package/dist/tests/domain/object-values/id.spec.js +0 -48
- package/dist/tests/domain/object-values/permission.spec.d.ts +0 -1
- package/dist/tests/domain/object-values/permission.spec.js +0 -75
- package/dist/tests/domain/object-values/role.spec.d.ts +0 -1
- package/dist/tests/domain/object-values/role.spec.js +0 -139
- package/dist/tests/domain/services/default-password-policy.spec.d.ts +0 -1
- package/dist/tests/domain/services/default-password-policy.spec.js +0 -69
- package/dist/tests/doman/entities/credential.spec.d.ts +0 -1
- package/dist/tests/doman/entities/credential.spec.js +0 -93
- package/dist/tests/doman/entities/user.spec.d.ts +0 -1
- package/dist/tests/doman/entities/user.spec.js +0 -93
- package/dist/tests/doman/object-values/email.spec.d.ts +0 -1
- package/dist/tests/doman/object-values/email.spec.js +0 -77
- package/dist/tests/doman/object-values/hashed-password.spec.d.ts +0 -1
- package/dist/tests/doman/object-values/hashed-password.spec.js +0 -54
- package/dist/tests/doman/object-values/id.spec.d.ts +0 -1
- package/dist/tests/doman/object-values/id.spec.js +0 -48
- package/dist/tests/doman/object-values/permission.spec.d.ts +0 -1
- package/dist/tests/doman/object-values/permission.spec.js +0 -75
- package/dist/tests/doman/object-values/role.spec.d.ts +0 -1
- package/dist/tests/doman/object-values/role.spec.js +0 -139
- package/dist/tests/helpers/make-jwt-subject.d.ts +0 -7
- package/dist/tests/helpers/make-jwt-subject.js +0 -16
- package/dist/tests/helpers/make-jwt-user.d.ts +0 -7
- package/dist/tests/helpers/make-jwt-user.js +0 -16
- package/dist/tests/helpers/make-user.d.ts +0 -2
- package/dist/tests/helpers/make-user.js +0 -15
- package/dist/tests/infrastructure/jwt/signature-strategy-factory.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/signature-strategy-factory.spec.js +0 -127
- package/dist/tests/infrastructure/jwt/strategies/ecdsa-signature-strategy.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/strategies/ecdsa-signature-strategy.spec.js +0 -157
- package/dist/tests/infrastructure/jwt/strategies/hmac-signature-strategy.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/strategies/hmac-signature-strategy.spec.js +0 -150
- package/dist/tests/infrastructure/jwt/strategies/rsa-signature-strategy..spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/strategies/rsa-signature-strategy..spec.js +0 -156
- package/dist/tests/infrastructure/jwt/token/actions/jwt-token-generator.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/token/actions/jwt-token-generator.spec.js +0 -179
- package/dist/tests/infrastructure/jwt/token/actions/jwt-token-verifier.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/token/actions/jwt-token-verifier.spec.js +0 -142
- package/dist/tests/infrastructure/jwt/token/jwt-signer.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/token/jwt-signer.spec.js +0 -125
- package/dist/tests/infrastructure/jwt/token/jwt-token-parser.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/token/jwt-token-parser.spec.js +0 -116
- package/dist/tests/infrastructure/jwt/token/jwt-token-validator.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/token/jwt-token-validator.spec.js +0 -88
- package/dist/tests/infrastructure/jwt/token/tools/jwt-signer.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/token/tools/jwt-signer.spec.js +0 -126
- package/dist/tests/infrastructure/jwt/token/tools/jwt-token-parser.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/token/tools/jwt-token-parser.spec.js +0 -116
- package/dist/tests/infrastructure/jwt/token/tools/jwt-token-validator.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/token/tools/jwt-token-validator.spec.js +0 -88
- package/dist/tests/infrastructure/security/security/bcrypt-password-hasher.spec.d.ts +0 -1
- package/dist/tests/infrastructure/security/security/bcrypt-password-hasher.spec.js +0 -37
- package/dist/tests/infrastructure/services/jwt-token-service.spec.d.ts +0 -1
- package/dist/tests/infrastructure/services/jwt-token-service.spec.js +0 -145
- package/dist/tests/infrastructure/services/token-session.service.spec.d.ts +0 -1
- package/dist/tests/infrastructure/services/token-session.service.spec.js +0 -269
- package/dist/tests/shared/constants/jwt-algorithms.spec.d.ts +0 -1
- package/dist/tests/shared/constants/jwt-algorithms.spec.js +0 -27
- package/dist/tests/shared/encoders/base64-url-encoder.spec.d.ts +0 -1
- package/dist/tests/shared/encoders/base64-url-encoder.spec.js +0 -70
- package/dist/tests/shared/utils/time-parser.spec.d.ts +0 -1
- package/dist/tests/shared/utils/time-parser.spec.js +0 -80
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.js +0 -17
- package/dist/utils/time-parser.d.ts +0 -28
- package/dist/utils/time-parser.js +0 -76
- /package/dist/{src/application/dtos/login.dto.js → application/dtos/request/login.request.js} +0 -0
- /package/dist/{src/application/dtos/logout.dto.js → application/dtos/request/logout.request.js} +0 -0
- /package/dist/{src/application/dtos/refresh-token.dto.js → application/dtos/request/refresh-token.request.js} +0 -0
- /package/dist/{src/application/dtos/register-user.dto.js → application/dtos/request/register-user.request.js} +0 -0
- /package/dist/{src/domain/ports/auth/password-hasher.js → application/dtos/response/login.response.js} +0 -0
- /package/dist/{src/domain/ports/auth/password-policy.port.js → application/dtos/response/logout.response.js} +0 -0
- /package/dist/{src/domain/ports/jwt/factory/signature-strategy-factory.port.js → application/dtos/response/refresh-token.response.js} +0 -0
- /package/dist/{src/domain/ports/jwt/payload/jwt-payload.port.js → application/dtos/response/register-user.response.js} +0 -0
- /package/dist/{src/domain/ports/jwt/signature-strategy-factory.port.js → application/dtos/type/user-role.type.js} +0 -0
- /package/dist/{src/application → application}/factories/index.d.ts +0 -0
- /package/dist/{src/application → application}/factories/index.js +0 -0
- /package/dist/{src/domain/ports/repository/credential.repository.js → application/types/auth-service-factory-options.type.js} +0 -0
- /package/dist/{src/application → application}/use-cases/index.d.ts +0 -0
- /package/dist/{src/application → application}/use-cases/index.js +0 -0
- /package/dist/{src/domain → domain}/entities/credential.entity.d.ts +0 -0
- /package/dist/{src/domain → domain}/entities/credential.entity.js +0 -0
- /package/dist/{src/domain → domain}/entities/index.d.ts +0 -0
- /package/dist/{src/domain → domain}/entities/index.js +0 -0
- /package/dist/{src/domain → domain}/entities/user.entity.d.ts +0 -0
- /package/dist/{src/domain → domain}/entities/user.entity.js +0 -0
- /package/dist/{src/domain → domain}/errors/identity.errors.d.ts +0 -0
- /package/dist/{src/domain → domain}/errors/identity.errors.js +0 -0
- /package/dist/{src/domain → domain}/errors/index.d.ts +0 -0
- /package/dist/{src/domain → domain}/errors/index.js +0 -0
- /package/dist/{src/domain → domain}/object-values/email.d.ts +0 -0
- /package/dist/{src/domain → domain}/object-values/email.js +0 -0
- /package/dist/{src/domain → domain}/object-values/hashed-password.d.ts +0 -0
- /package/dist/{src/domain → domain}/object-values/hashed-password.js +0 -0
- /package/dist/{src/domain → domain}/object-values/id.d.ts +0 -0
- /package/dist/{src/domain → domain}/object-values/id.js +0 -0
- /package/dist/{src/domain → domain}/object-values/index.d.ts +0 -0
- /package/dist/{src/domain → domain}/object-values/index.js +0 -0
- /package/dist/{src/domain → domain}/object-values/permission.d.ts +0 -0
- /package/dist/{src/domain → domain}/object-values/permission.js +0 -0
- /package/dist/{src/domain → domain}/object-values/role.d.ts +0 -0
- /package/dist/{src/domain → domain}/object-values/role.js +0 -0
- /package/dist/{src/domain/ports/repository/user.repository.js → domain/ports/auth/password-hasher.port.js} +0 -0
- /package/dist/{src/domain/ports/token/token-session.port.js → domain/ports/auth/password-policy.port.js} +0 -0
- /package/dist/{src/domain → domain}/ports/jwt/payload/jwt-payload.port.d.ts +0 -0
- /package/dist/{src/domain/ports/token/token.service.port.js → domain/ports/jwt/payload/jwt-payload.port.js} +0 -0
- /package/dist/{src/domain/props/entities/credential.props.js → domain/ports/repository/credential.repository.js} +0 -0
- /package/dist/{src/domain/props/entities/user.props.js → domain/ports/repository/user-repository.port.js} +0 -0
- /package/dist/{src/domain/props/jwt/create-payload.props.js → domain/ports/token/token-session.port.js} +0 -0
- /package/dist/{src/domain/services → domain/ports/token}/token.service.port.js +0 -0
- /package/dist/{src/domain → domain}/props/entities/credential.props.d.ts +0 -0
- /package/dist/{src/domain/props/jwt/generate-access-token.props.js → domain/props/entities/credential.props.js} +0 -0
- /package/dist/{src/domain → domain}/props/entities/index.d.ts +0 -0
- /package/dist/{src/domain → domain}/props/entities/index.js +0 -0
- /package/dist/{src/domain → domain}/props/entities/user.props.d.ts +0 -0
- /package/dist/{src/domain/props/jwt/generate-refresh-token.props.js → domain/props/entities/user.props.js} +0 -0
- /package/dist/{src/domain → domain}/props/index.d.ts +0 -0
- /package/dist/{src/domain → domain}/props/index.js +0 -0
- /package/dist/{src/domain/props/services → domain/props/jwt}/generate-access-token.props.js +0 -0
- /package/dist/{src/domain/props/services → domain/props/jwt}/generate-refresh-token.props.js +0 -0
- /package/dist/{src/domain → domain}/props/jwt/jwt-user.d.ts +0 -0
- /package/dist/{src/domain → domain}/props/jwt/jwt-user.js +0 -0
- /package/dist/{src/domain → domain}/services/index.d.ts +0 -0
- /package/dist/{src/domain → domain}/services/index.js +0 -0
- /package/dist/{src/domain → domain}/services/password-policy.service.js +0 -0
- /package/dist/{src/infrastructure/repositories/test → in-memory}/in-memory-user.repository.js +0 -0
- /package/dist/{src/infrastructure/repositories/test → in-memory}/index.d.ts +0 -0
- /package/dist/{src/infrastructure/repositories/test → in-memory}/index.js +0 -0
- /package/dist/{src/domain/ports/auth/password-policy-config.port.d.ts → infrastructure/index.d.ts} +0 -0
- /package/dist/{src/infrastructure → infrastructure}/security/index.d.ts +0 -0
- /package/dist/{src/infrastructure → infrastructure}/security/index.js +0 -0
- /package/dist/{src/infrastructure → infrastructure}/types/auth-service-container.js +0 -0
- /package/dist/{src/infrastructure → infrastructure}/types/index.d.ts +0 -0
- /package/dist/{src/infrastructure → infrastructure}/types/index.js +0 -0
- /package/dist/{src/shared → shared}/utils/index.d.ts +0 -0
- /package/dist/{src/shared → shared}/utils/index.js +0 -0
- /package/dist/{src/shared → shared}/utils/time-parser.d.ts +0 -0
- /package/dist/{src/shared → shared}/utils/time-parser.js +0 -0
|
@@ -1,157 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,150 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,156 +0,0 @@
|
|
|
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("RcaSignatureStrategy", () => {
|
|
40
|
-
// 🔑 Función auxiliar para generar un par de claves RSA
|
|
41
|
-
const makeKeys = (modulusLength = 2048) => crypto.generateKeyPairSync("rsa", {
|
|
42
|
-
modulusLength, // Tamaño de la clave (bits)
|
|
43
|
-
publicKeyEncoding: { type: "spki", format: "pem" },
|
|
44
|
-
privateKeyEncoding: { type: "pkcs8", format: "pem" },
|
|
45
|
-
});
|
|
46
|
-
// Datos base para firmar
|
|
47
|
-
const baseData = "header.payload";
|
|
48
|
-
// Vectores de prueba para cada algoritmo HMAC
|
|
49
|
-
const vectors = [
|
|
50
|
-
{ alg: shared_1.algorithms.rsa.RS256, hash: "sha256" },
|
|
51
|
-
{ alg: shared_1.algorithms.rsa.RS384, hash: "sha384" },
|
|
52
|
-
{ alg: shared_1.algorithms.rsa.RS512, hash: "sha512" },
|
|
53
|
-
];
|
|
54
|
-
// Casos positivos
|
|
55
|
-
it.each(vectors)("sign/verify OK para %s", ({ alg }) => {
|
|
56
|
-
// Genera par de claves
|
|
57
|
-
const { publicKey, privateKey } = makeKeys(2048);
|
|
58
|
-
// Crea la estrategia
|
|
59
|
-
const encoder = new shared_1.Base64UrlEncoder();
|
|
60
|
-
// Crea la estrategia
|
|
61
|
-
const strat = new infrastructure_1.RsaSignatureStrategy(alg, encoder);
|
|
62
|
-
// Firma
|
|
63
|
-
const sig = strat.sign(baseData, privateKey);
|
|
64
|
-
// Debe ser Base64URL (sin +, /, =)
|
|
65
|
-
expect(sig).toMatch(/^[A-Za-z0-9\-_]+$/);
|
|
66
|
-
// verify OK con los mismos datos/clave
|
|
67
|
-
expect(strat.verify(baseData, sig, publicKey)).toBe(true);
|
|
68
|
-
});
|
|
69
|
-
// Casos negativos
|
|
70
|
-
it.each(vectors)("verify=false si los datos se alteran (%s)", ({ alg }) => {
|
|
71
|
-
// Genera par de claves
|
|
72
|
-
const { publicKey, privateKey } = makeKeys();
|
|
73
|
-
// Crea la estrategia
|
|
74
|
-
const encoder = new shared_1.Base64UrlEncoder();
|
|
75
|
-
// Crea la estrategia
|
|
76
|
-
const strat = new infrastructure_1.RsaSignatureStrategy(alg, encoder);
|
|
77
|
-
// Firma
|
|
78
|
-
const sig = strat.sign(baseData, privateKey);
|
|
79
|
-
// verify debe fallar si se alteran los datos
|
|
80
|
-
expect(strat.verify(baseData + ".tampered", sig, publicKey)).toBe(false);
|
|
81
|
-
});
|
|
82
|
-
// Casos negativos - firma alterada
|
|
83
|
-
it.each(vectors)("verify=false si la firma se altera (%s)", ({ alg }) => {
|
|
84
|
-
// Genera par de claves
|
|
85
|
-
const { publicKey, privateKey } = makeKeys();
|
|
86
|
-
// Crea la estrategia
|
|
87
|
-
const encoder = new shared_1.Base64UrlEncoder();
|
|
88
|
-
// Crea la estrategia
|
|
89
|
-
const strat = new infrastructure_1.RsaSignatureStrategy(alg, encoder);
|
|
90
|
-
// Firma
|
|
91
|
-
const sig = strat.sign(baseData, privateKey);
|
|
92
|
-
// Decodificamos a base64 estándar y luego a bytes
|
|
93
|
-
const stdB64 = encoder.decode(sig);
|
|
94
|
-
const buf = Buffer.from(stdB64, "base64");
|
|
95
|
-
// Flip de un byte en el medio (afecta r/s con alta probabilidad)
|
|
96
|
-
const i = Math.floor(buf.length / 2);
|
|
97
|
-
buf[i] ^= 0x01;
|
|
98
|
-
// Re-encode a base64url para pasar por la API pública de la estrategia
|
|
99
|
-
const tampered = encoder.encode(Buffer.from(buf).toString("base64"));
|
|
100
|
-
expect(strat.verify(baseData, tampered, publicKey)).toBe(false);
|
|
101
|
-
});
|
|
102
|
-
// Pruebas adicionales
|
|
103
|
-
it("getSupportedAlgorithm() devuelve el algoritmo configurado", () => {
|
|
104
|
-
// Crea la estrategia
|
|
105
|
-
const encoder = new shared_1.Base64UrlEncoder();
|
|
106
|
-
// Crea la estrategia
|
|
107
|
-
const strat = new infrastructure_1.RsaSignatureStrategy(shared_1.algorithms.rsa.RS256, encoder);
|
|
108
|
-
// Debe devolver el algoritmo configurado
|
|
109
|
-
expect(strat.getSupportedAlgorithm()).toBe("RS256");
|
|
110
|
-
});
|
|
111
|
-
// Casos de error - algoritmo no soportado
|
|
112
|
-
it("sign lanza y verify devuelve false para algoritmo no soportado", () => {
|
|
113
|
-
// Crea la estrategia con un algoritmo inválido
|
|
114
|
-
const badAlg = "RS999";
|
|
115
|
-
// Crea la estrategia
|
|
116
|
-
const encoder = new shared_1.Base64UrlEncoder();
|
|
117
|
-
// Crea la estrategia
|
|
118
|
-
const strat = new infrastructure_1.RsaSignatureStrategy(badAlg, encoder);
|
|
119
|
-
// Genera par de claves válidas
|
|
120
|
-
const { publicKey, privateKey } = makeKeys(2048);
|
|
121
|
-
// sign debe lanzar error
|
|
122
|
-
expect(() => strat.sign(baseData, privateKey)).toThrow(/Unsupported RSA algorithm/i);
|
|
123
|
-
// verify debe devolver false
|
|
124
|
-
expect(strat.verify(baseData, "abc", publicKey)).toBe(false);
|
|
125
|
-
});
|
|
126
|
-
// Prueba que se usa el encoder correctamente
|
|
127
|
-
it("usa el encoder para encode (sign) y decode (verify)", () => {
|
|
128
|
-
// Mocks del encoder
|
|
129
|
-
const encoder = {
|
|
130
|
-
encode: jest.fn((b64) => b64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "")),
|
|
131
|
-
decode: jest.fn((b64url) => {
|
|
132
|
-
const pad = b64url.length % 4;
|
|
133
|
-
let std = b64url.replace(/-/g, "+").replace(/_/g, "/");
|
|
134
|
-
if (pad)
|
|
135
|
-
std += "=".repeat(4 - pad);
|
|
136
|
-
return std;
|
|
137
|
-
}),
|
|
138
|
-
};
|
|
139
|
-
// Genera par de claves válidas
|
|
140
|
-
const { publicKey, privateKey } = makeKeys(2048);
|
|
141
|
-
// Crea la estrategia
|
|
142
|
-
const strat = new infrastructure_1.RsaSignatureStrategy(shared_1.algorithms.rsa.RS256, encoder);
|
|
143
|
-
// Firma
|
|
144
|
-
const sig = strat.sign(baseData, privateKey);
|
|
145
|
-
// Verifica que se llamó al encoder
|
|
146
|
-
expect(encoder.encode).toHaveBeenCalledTimes(1);
|
|
147
|
-
// El resultado debe ser string
|
|
148
|
-
expect(typeof sig).toBe("string");
|
|
149
|
-
// Verifica
|
|
150
|
-
const ok = strat.verify(baseData, sig, publicKey);
|
|
151
|
-
// Verifica que se llamó al decoder
|
|
152
|
-
expect(encoder.decode).toHaveBeenCalledTimes(1);
|
|
153
|
-
// El resultado debe ser true
|
|
154
|
-
expect(ok).toBe(true);
|
|
155
|
-
});
|
|
156
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
// Mocks
|
|
4
|
-
jest.mock("src/shared", () => {
|
|
5
|
-
// Mantiene el resto del módulo original
|
|
6
|
-
const actual = jest.requireActual("src/shared");
|
|
7
|
-
return {
|
|
8
|
-
// Mantiene todo lo anterior
|
|
9
|
-
...actual,
|
|
10
|
-
// Mockeamos solo TimeParser
|
|
11
|
-
TimeParser: {
|
|
12
|
-
parseToMilliseconds: jest.fn(),
|
|
13
|
-
},
|
|
14
|
-
};
|
|
15
|
-
});
|
|
16
|
-
const infrastructure_1 = require("src/infrastructure");
|
|
17
|
-
const shared_1 = require("src/shared");
|
|
18
|
-
const make_jwt_user_1 = require("../../../../helpers/make-jwt-user");
|
|
19
|
-
// Types: Simplificados para test no necesitamos toda la implementación solo la firma del método sign()
|
|
20
|
-
// y el encoder Base64UrlEncoder
|
|
21
|
-
// type JwtSigner = { sign: (input: string, secret: string) => string };
|
|
22
|
-
// type Base64UrlEncoder = { encode: (input: string) => string };
|
|
23
|
-
// Config type para los tests
|
|
24
|
-
// type JwtTokenServiceConfig = {
|
|
25
|
-
// accessTokenSecret: string;
|
|
26
|
-
// refreshTokenSecret: string;
|
|
27
|
-
// accessTokenExpirationMs: number;
|
|
28
|
-
// refreshTokenExpirationMs: number;
|
|
29
|
-
// issuer: string;
|
|
30
|
-
// audience: string;
|
|
31
|
-
// algorithm?: string;
|
|
32
|
-
// };
|
|
33
|
-
const FIXED_NOW_MS = Date.UTC(2025, 0, 1, 0, 0, 0, 0);
|
|
34
|
-
const FIXED_NOW_SECONDS = Math.floor(FIXED_NOW_MS / 1000);
|
|
35
|
-
// encoder como jest.fn para poder leer mock.calls
|
|
36
|
-
const encoderMock = {
|
|
37
|
-
encode: jest.fn((input) => {
|
|
38
|
-
if (input.includes('"typ":"JWT"'))
|
|
39
|
-
return "encodedHeader";
|
|
40
|
-
return "encodedPayload";
|
|
41
|
-
}),
|
|
42
|
-
decode: function (str) {
|
|
43
|
-
throw new Error("Function not implemented.");
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
// signer como jest.fn para poder leer mock.calls
|
|
47
|
-
const signerMock = {
|
|
48
|
-
sign: jest.fn().mockImplementation((data, key, algorithm) => {
|
|
49
|
-
return `signed(${data})`;
|
|
50
|
-
}),
|
|
51
|
-
verifySignature: jest.fn().mockImplementation((data, signature, key) => {
|
|
52
|
-
return signature === `signed(${data})`;
|
|
53
|
-
}),
|
|
54
|
-
};
|
|
55
|
-
// Config base para los tests
|
|
56
|
-
const baseConfig = {
|
|
57
|
-
accessTokenSecret: "ACCESS_SECRET_ABC",
|
|
58
|
-
refreshTokenSecret: "REFRESH_SECRET_DEF",
|
|
59
|
-
accessTokenExpirationMs: 60 * 60 * 1000, // 1h
|
|
60
|
-
refreshTokenExpirationMs: 7 * 24 * 60 * 60 * 1000, // 7d
|
|
61
|
-
issuer: "my-issuer",
|
|
62
|
-
audience: "my-audience",
|
|
63
|
-
algorithm: "HS256",
|
|
64
|
-
};
|
|
65
|
-
// Util: normaliza roles a string[]
|
|
66
|
-
function normalizeRole(r) {
|
|
67
|
-
if (typeof r === "string")
|
|
68
|
-
return r;
|
|
69
|
-
if (r && typeof r === "object") {
|
|
70
|
-
const o = r;
|
|
71
|
-
return String(o.role ?? o.name ?? o.value);
|
|
72
|
-
}
|
|
73
|
-
return String(r);
|
|
74
|
-
}
|
|
75
|
-
// Regex simple para UUID v4 (aceptable para test)
|
|
76
|
-
const UUID_V4 = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
77
|
-
describe("JwtTokenGenerator", () => {
|
|
78
|
-
// la instancia a testear
|
|
79
|
-
let generator;
|
|
80
|
-
// fija la fecha actual para tests consistentes
|
|
81
|
-
beforeAll(() => {
|
|
82
|
-
jest.useFakeTimers().setSystemTime(FIXED_NOW_MS);
|
|
83
|
-
});
|
|
84
|
-
// resetea mocks y crea nueva instancia antes de cada test
|
|
85
|
-
beforeEach(() => {
|
|
86
|
-
jest.clearAllMocks();
|
|
87
|
-
generator = new infrastructure_1.JwtTokenGenerator(encoderMock, signerMock);
|
|
88
|
-
});
|
|
89
|
-
// restaura timers reales
|
|
90
|
-
afterAll(() => {
|
|
91
|
-
jest.useRealTimers();
|
|
92
|
-
});
|
|
93
|
-
// Testea generación de Access Token
|
|
94
|
-
test("generateAccessToken: usa accessTokenSecret y expiración por defecto del config cuando no hay expiresIn", () => {
|
|
95
|
-
// crea un user de prueba
|
|
96
|
-
const user = (0, make_jwt_user_1.makeJwtSubject)();
|
|
97
|
-
// genera el token
|
|
98
|
-
const token = generator.generateAccessToken({
|
|
99
|
-
user: user,
|
|
100
|
-
config: { ...baseConfig, algorithm: "HS256" },
|
|
101
|
-
});
|
|
102
|
-
expect(signerMock.sign).toHaveBeenCalledWith("encodedHeader.encodedPayload", baseConfig.accessTokenSecret, baseConfig.algorithm);
|
|
103
|
-
expect(token).toBe("encodedHeader.encodedPayload.signed(encodedHeader.encodedPayload)");
|
|
104
|
-
const encodeCalls = encoderMock.encode.mock.calls;
|
|
105
|
-
const payloadJson = encodeCalls[1][0];
|
|
106
|
-
const payload = JSON.parse(payloadJson);
|
|
107
|
-
// jti no debe ser fijo: validamos que sea string y UUID-ish
|
|
108
|
-
expect(typeof payload.jti).toBe("string");
|
|
109
|
-
// Si tu runtime no garantiza v4, cambia a expect.any(String)
|
|
110
|
-
expect(payload.jti).toMatch(UUID_V4);
|
|
111
|
-
// normalizamos roles y comparamos
|
|
112
|
-
const roleNames = payload.roles.map(normalizeRole);
|
|
113
|
-
expect(roleNames).toEqual(["ADMIN", "USER"]);
|
|
114
|
-
expect(payload).toMatchObject({
|
|
115
|
-
sub: "user-123",
|
|
116
|
-
customClaims: {},
|
|
117
|
-
iat: FIXED_NOW_SECONDS,
|
|
118
|
-
exp: FIXED_NOW_SECONDS + 60 * 60,
|
|
119
|
-
iss: "my-issuer",
|
|
120
|
-
aud: "my-audience",
|
|
121
|
-
});
|
|
122
|
-
const headerJson = encodeCalls[0][0];
|
|
123
|
-
const header = JSON.parse(headerJson);
|
|
124
|
-
expect(header).toEqual({ alg: "HS256", typ: "JWT" });
|
|
125
|
-
});
|
|
126
|
-
test("generateAccessToken: respeta expiresIn string (usa TimeParser.parseToMilliseconds)", () => {
|
|
127
|
-
const user = (0, make_jwt_user_1.makeJwtSubject)();
|
|
128
|
-
shared_1.TimeParser.parseToMilliseconds.mockReturnValueOnce(15 * 60 * 1000); // 15m
|
|
129
|
-
const token = generator.generateAccessToken({
|
|
130
|
-
user: user,
|
|
131
|
-
config: baseConfig,
|
|
132
|
-
expiresIn: "15m",
|
|
133
|
-
customClaims: { plan: "pro" },
|
|
134
|
-
});
|
|
135
|
-
expect(token).toBe("encodedHeader.encodedPayload.signed(encodedHeader.encodedPayload)");
|
|
136
|
-
expect(shared_1.TimeParser.parseToMilliseconds).toHaveBeenCalledWith("15m");
|
|
137
|
-
const payloadJson = encoderMock.encode.mock.calls[1][0];
|
|
138
|
-
const payload = JSON.parse(payloadJson);
|
|
139
|
-
const roleNames = payload.roles.map(normalizeRole);
|
|
140
|
-
expect(roleNames).toEqual(["ADMIN", "USER"]);
|
|
141
|
-
expect(payload.exp).toBe(FIXED_NOW_SECONDS + 15 * 60);
|
|
142
|
-
expect(payload.customClaims).toEqual({ plan: "pro" });
|
|
143
|
-
});
|
|
144
|
-
test("generateRefreshToken: usa refreshTokenSecret y expiración por defecto de refresh", () => {
|
|
145
|
-
const user = (0, make_jwt_user_1.makeJwtSubject)();
|
|
146
|
-
const token = generator.generateRefreshToken({
|
|
147
|
-
user: user,
|
|
148
|
-
config: { ...baseConfig, algorithm: "ES256" },
|
|
149
|
-
});
|
|
150
|
-
expect(signerMock.sign).toHaveBeenCalledWith("encodedHeader.encodedPayload", baseConfig.refreshTokenSecret, "ES256");
|
|
151
|
-
expect(token).toBe("encodedHeader.encodedPayload.signed(encodedHeader.encodedPayload)");
|
|
152
|
-
const headerJson = encoderMock.encode.mock.calls[0][0];
|
|
153
|
-
const header = JSON.parse(headerJson);
|
|
154
|
-
expect(header).toEqual({ alg: "ES256", typ: "JWT" });
|
|
155
|
-
const payloadJson = encoderMock.encode.mock.calls[1][0];
|
|
156
|
-
const payload = JSON.parse(payloadJson);
|
|
157
|
-
expect(payload.exp).toBe(FIXED_NOW_SECONDS + 7 * 24 * 60 * 60);
|
|
158
|
-
});
|
|
159
|
-
test("cuando no hay customClaims en props, se usa {}", () => {
|
|
160
|
-
const user = (0, make_jwt_user_1.makeJwtSubject)();
|
|
161
|
-
generator.generateAccessToken({
|
|
162
|
-
user: user,
|
|
163
|
-
config: baseConfig,
|
|
164
|
-
});
|
|
165
|
-
const payloadJson = encoderMock.encode.mock.calls[1][0];
|
|
166
|
-
const payload = JSON.parse(payloadJson);
|
|
167
|
-
expect(payload.customClaims).toEqual({});
|
|
168
|
-
});
|
|
169
|
-
test("firma exactamente 'header.payload' y concatena '.signature'", () => {
|
|
170
|
-
const user = (0, make_jwt_user_1.makeJwtSubject)();
|
|
171
|
-
const token = generator.generateAccessToken({
|
|
172
|
-
user: user,
|
|
173
|
-
config: baseConfig,
|
|
174
|
-
});
|
|
175
|
-
expect(signerMock.sign).toHaveBeenCalledTimes(1);
|
|
176
|
-
expect(signerMock.sign).toHaveBeenCalledWith("encodedHeader.encodedPayload", baseConfig.accessTokenSecret, baseConfig.algorithm);
|
|
177
|
-
expect(token).toBe("encodedHeader.encodedPayload.signed(encodedHeader.encodedPayload)");
|
|
178
|
-
});
|
|
179
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|