@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,142 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const errors_1 = require("src/domain/errors");
|
|
4
|
-
const infrastructure_1 = require("src/infrastructure");
|
|
5
|
-
describe("JwtTokenVerifier", () => {
|
|
6
|
-
let signer;
|
|
7
|
-
let parser;
|
|
8
|
-
let verifier;
|
|
9
|
-
let config;
|
|
10
|
-
const algorithm = "HS256";
|
|
11
|
-
const NOW_MS = Date.UTC(2025, 0, 1, 0, 0, 0); // 2025-01-01T00:00:00Z
|
|
12
|
-
const NOW_SECONDS = Math.floor(NOW_MS / 1000);
|
|
13
|
-
beforeAll(() => {
|
|
14
|
-
jest.useFakeTimers().setSystemTime(NOW_MS);
|
|
15
|
-
});
|
|
16
|
-
beforeEach(() => {
|
|
17
|
-
signer = {
|
|
18
|
-
verifySignature: jest.fn(),
|
|
19
|
-
};
|
|
20
|
-
parser = {
|
|
21
|
-
extractParts: jest.fn(),
|
|
22
|
-
parseAndValidatePayload: jest.fn(),
|
|
23
|
-
parsePayload: jest.fn(),
|
|
24
|
-
};
|
|
25
|
-
verifier = new infrastructure_1.JwtTokenVerifier(signer, // no nos importa la implementación real aquí
|
|
26
|
-
parser, algorithm);
|
|
27
|
-
config = {
|
|
28
|
-
accessTokenSecret: "ACCESS_SECRET",
|
|
29
|
-
refreshTokenSecret: "REFRESH_SECRET",
|
|
30
|
-
accessTokenExpirationMs: 15 * 60 * 1000,
|
|
31
|
-
refreshTokenExpirationMs: 7 * 24 * 60 * 60 * 1000,
|
|
32
|
-
issuer: "test-issuer",
|
|
33
|
-
audience: "test-audience",
|
|
34
|
-
algorithm: "HS256",
|
|
35
|
-
};
|
|
36
|
-
});
|
|
37
|
-
afterAll(() => {
|
|
38
|
-
jest.useRealTimers();
|
|
39
|
-
});
|
|
40
|
-
test("verifyAccessToken: firma válida y token no expirado devuelve payload normalizado", () => {
|
|
41
|
-
const token = "headerPart.payloadPart.signaturePart";
|
|
42
|
-
parser.extractParts.mockReturnValue([
|
|
43
|
-
"headerPart",
|
|
44
|
-
"payloadPart",
|
|
45
|
-
"signaturePart",
|
|
46
|
-
]);
|
|
47
|
-
const rawPayload = {
|
|
48
|
-
sub: "user-123",
|
|
49
|
-
roles: [{ role: "ADMIN" }, { role: "USER" }],
|
|
50
|
-
customClaims: { foo: "bar" },
|
|
51
|
-
iat: NOW_SECONDS,
|
|
52
|
-
exp: NOW_SECONDS + 60 * 60, // +1h
|
|
53
|
-
jti: "jti-123",
|
|
54
|
-
iss: "test-issuer",
|
|
55
|
-
aud: "test-audience",
|
|
56
|
-
};
|
|
57
|
-
signer.verifySignature.mockReturnValue(true);
|
|
58
|
-
parser.parseAndValidatePayload.mockReturnValue(rawPayload);
|
|
59
|
-
const result = verifier.verifyAccessToken(token, config);
|
|
60
|
-
// Verifica que use el accessTokenSecret
|
|
61
|
-
expect(signer.verifySignature).toHaveBeenCalledWith("headerPart.payloadPart", "signaturePart", "ACCESS_SECRET", "HS256");
|
|
62
|
-
expect(parser.extractParts).toHaveBeenCalledWith(token);
|
|
63
|
-
expect(parser.parseAndValidatePayload).toHaveBeenCalledWith("payloadPart");
|
|
64
|
-
// Verifica el payload normalizado
|
|
65
|
-
expect(result).toEqual({
|
|
66
|
-
sub: "user-123",
|
|
67
|
-
roles: [
|
|
68
|
-
{
|
|
69
|
-
role: "ADMIN",
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
role: "USER",
|
|
73
|
-
},
|
|
74
|
-
],
|
|
75
|
-
customClaims: { foo: "bar" },
|
|
76
|
-
iat: rawPayload.iat,
|
|
77
|
-
exp: rawPayload.exp,
|
|
78
|
-
jti: rawPayload.jti,
|
|
79
|
-
iss: rawPayload.iss,
|
|
80
|
-
aud: rawPayload.aud,
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
test("verifyRefreshToken: usa refreshTokenSecret para verificar la firma", () => {
|
|
84
|
-
const token = "h.p.s";
|
|
85
|
-
parser.extractParts.mockReturnValue(["h64", "p64", "s64"]);
|
|
86
|
-
signer.verifySignature.mockReturnValue(true);
|
|
87
|
-
parser.parseAndValidatePayload.mockReturnValue({
|
|
88
|
-
userId: "user-123",
|
|
89
|
-
role: [],
|
|
90
|
-
customClaims: {},
|
|
91
|
-
iat: NOW_SECONDS,
|
|
92
|
-
exp: NOW_SECONDS + 10,
|
|
93
|
-
jti: "jti",
|
|
94
|
-
iss: "test-issuer",
|
|
95
|
-
aud: "test-audience",
|
|
96
|
-
});
|
|
97
|
-
verifier.verifyRefreshToken(token, config);
|
|
98
|
-
expect(signer.verifySignature).toHaveBeenCalledWith("h64.p64", "s64", "REFRESH_SECRET", "HS256");
|
|
99
|
-
});
|
|
100
|
-
test("verifyAccessToken: firma inválida lanza InvalidSignatureError", () => {
|
|
101
|
-
const token = "h.p.s";
|
|
102
|
-
parser.extractParts.mockReturnValue(["h64", "p64", "s64"]);
|
|
103
|
-
signer.verifySignature.mockReturnValue(false);
|
|
104
|
-
expect(() => verifier.verifyAccessToken(token, config)).toThrow(errors_1.InvalidSignatureError);
|
|
105
|
-
// No debería intentar parsear el payload si la firma es inválida
|
|
106
|
-
expect(parser.parseAndValidatePayload).not.toHaveBeenCalled();
|
|
107
|
-
});
|
|
108
|
-
test("verifyAccessToken: token expirado lanza TokenExpiredError", () => {
|
|
109
|
-
const token = "h.p.s";
|
|
110
|
-
parser.extractParts.mockReturnValue(["h64", "p64", "s64"]);
|
|
111
|
-
signer.verifySignature.mockReturnValue(true);
|
|
112
|
-
const expiredPayload = {
|
|
113
|
-
userId: "user-123",
|
|
114
|
-
role: ["USER"],
|
|
115
|
-
customClaims: {},
|
|
116
|
-
iat: NOW_SECONDS - 10,
|
|
117
|
-
exp: NOW_SECONDS - 1, // ya expirado
|
|
118
|
-
jti: "jti-expired",
|
|
119
|
-
iss: "test-issuer",
|
|
120
|
-
aud: "test-audience",
|
|
121
|
-
};
|
|
122
|
-
parser.parseAndValidatePayload.mockReturnValue(expiredPayload);
|
|
123
|
-
expect(() => verifier.verifyAccessToken(token, config)).toThrow(errors_1.TokenExpiredError);
|
|
124
|
-
});
|
|
125
|
-
test("getTokenExpiration: devuelve la fecha basada en el exp del payload", () => {
|
|
126
|
-
const token = "header.payload.signature";
|
|
127
|
-
parser.parsePayload.mockReturnValue({
|
|
128
|
-
// Solo necesitamos exp aquí
|
|
129
|
-
exp: NOW_SECONDS + 3600,
|
|
130
|
-
iat: NOW_SECONDS,
|
|
131
|
-
jti: "jti",
|
|
132
|
-
iss: "iss",
|
|
133
|
-
aud: "aud",
|
|
134
|
-
sub: "user-123",
|
|
135
|
-
roles: [],
|
|
136
|
-
customClaims: {},
|
|
137
|
-
});
|
|
138
|
-
const expiresAt = verifier.getTokenExpiration(token);
|
|
139
|
-
expect(parser.parsePayload).toHaveBeenCalledWith(token);
|
|
140
|
-
expect(expiresAt.getTime()).toBe((NOW_SECONDS + 3600) * 1000);
|
|
141
|
-
});
|
|
142
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const jwt_1 = require("src/infrastructure/jwt");
|
|
4
|
-
const token_1 = require("src/infrastructure/jwt/token");
|
|
5
|
-
const shared_1 = require("src/shared");
|
|
6
|
-
// ────────────────────────────────────────────────────────────────
|
|
7
|
-
// Mock de SignatureStrategyFactory y su comportamiento
|
|
8
|
-
// ────────────────────────────────────────────────────────────────
|
|
9
|
-
jest.mock("src/infrastructure/jwt/signature-strategy.factory");
|
|
10
|
-
describe("JwtSigner", () => {
|
|
11
|
-
// Variables comunes para las pruebas
|
|
12
|
-
let signer;
|
|
13
|
-
let factoryMock;
|
|
14
|
-
let encoder;
|
|
15
|
-
// ────────────────────────────────────────────────────────────────
|
|
16
|
-
// Configuración antes de cada prueba
|
|
17
|
-
// ────────────────────────────────────────────────────────────────
|
|
18
|
-
beforeEach(() => {
|
|
19
|
-
// Instancia real del codificador
|
|
20
|
-
encoder = new shared_1.Base64UrlEncoder();
|
|
21
|
-
// Mock de factory.create() → devuelve una estrategia con sign/verify falsos
|
|
22
|
-
factoryMock = {
|
|
23
|
-
create: jest.fn(),
|
|
24
|
-
};
|
|
25
|
-
// Forzar el constructor de SignatureStrategyFactory para devolver nuestro mock
|
|
26
|
-
jwt_1.SignatureStrategyFactory.mockImplementation(() => factoryMock);
|
|
27
|
-
// Crea la instancia de JwtSigner que vamos a probar
|
|
28
|
-
signer = new token_1.JwtSigner(encoder);
|
|
29
|
-
});
|
|
30
|
-
// Limpia los mocks después de cada prueba
|
|
31
|
-
afterEach(() => {
|
|
32
|
-
jest.clearAllMocks();
|
|
33
|
-
});
|
|
34
|
-
// ────────────────────────────────────────────────────────────────
|
|
35
|
-
// sign()
|
|
36
|
-
// ────────────────────────────────────────────────────────────────
|
|
37
|
-
describe("sign", () => {
|
|
38
|
-
// Prueba básica de firma
|
|
39
|
-
test("firma datos usando la estrategia devuelta por la fábrica", () => {
|
|
40
|
-
// Prepara la estrategia mock
|
|
41
|
-
const fakeSignature = "signed-data";
|
|
42
|
-
const mockStrategy = { sign: jest.fn().mockReturnValue(fakeSignature) };
|
|
43
|
-
factoryMock.create.mockReturnValue(mockStrategy);
|
|
44
|
-
// Llama al método a probar
|
|
45
|
-
const result = signer.sign("header.payload", "secret-key", "HS256");
|
|
46
|
-
// Verificaciones
|
|
47
|
-
// Asegura que la fábrica fue llamada con el algoritmo correcto
|
|
48
|
-
expect(factoryMock.create).toHaveBeenCalledWith("HS256");
|
|
49
|
-
// Asegura que la estrategia firmó los datos correctamente
|
|
50
|
-
expect(mockStrategy.sign).toHaveBeenCalledWith("header.payload", "secret-key");
|
|
51
|
-
// Asegura que el resultado es el esperado
|
|
52
|
-
expect(result).toBe(fakeSignature);
|
|
53
|
-
});
|
|
54
|
-
// Prueba el valor por defecto del algoritmo
|
|
55
|
-
test("usa 'HS256' como algoritmo por defecto si no se especifica", () => {
|
|
56
|
-
// Prepara la estrategia mock
|
|
57
|
-
const mockStrategy = { sign: jest.fn().mockReturnValue("sig") };
|
|
58
|
-
factoryMock.create.mockReturnValue(mockStrategy);
|
|
59
|
-
// Llama al método sin especificar algoritmo
|
|
60
|
-
signer.sign("abc.def", "key");
|
|
61
|
-
// Verifica que se usó el algoritmo por defecto
|
|
62
|
-
expect(factoryMock.create).toHaveBeenCalledWith("HS256");
|
|
63
|
-
// Asegura que la estrategia fue llamada una vez
|
|
64
|
-
expect(mockStrategy.sign).toHaveBeenCalledTimes(1);
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
// ────────────────────────────────────────────────────────────────
|
|
68
|
-
// verifySignature()
|
|
69
|
-
// ────────────────────────────────────────────────────────────────
|
|
70
|
-
describe("verifySignature", () => {
|
|
71
|
-
// Prueba básica de verificación
|
|
72
|
-
test("verifica correctamente usando la estrategia devuelta por la fábrica", () => {
|
|
73
|
-
// Prepara la estrategia mock
|
|
74
|
-
const mockStrategy = { verify: jest.fn().mockReturnValue(true) };
|
|
75
|
-
factoryMock.create.mockReturnValue(mockStrategy);
|
|
76
|
-
// Llama al método a probar
|
|
77
|
-
const result = signer.verifySignature("header.payload", "signature", "secret", "HS512");
|
|
78
|
-
// Verificaciones
|
|
79
|
-
// Asegura que la fábrica fue llamada con el algoritmo correcto
|
|
80
|
-
expect(factoryMock.create).toHaveBeenCalledWith("HS512");
|
|
81
|
-
// Asegura que la estrategia verificó los datos correctamente
|
|
82
|
-
expect(mockStrategy.verify).toHaveBeenCalledWith("header.payload", "signature", "secret");
|
|
83
|
-
// Asegura que el resultado es el esperado
|
|
84
|
-
expect(result).toBe(true);
|
|
85
|
-
});
|
|
86
|
-
// Prueba cuando la verificación falla
|
|
87
|
-
test("retorna false si verify devuelve false", () => {
|
|
88
|
-
// Prepara la estrategia mock
|
|
89
|
-
const mockStrategy = { verify: jest.fn().mockReturnValue(false) };
|
|
90
|
-
factoryMock.create.mockReturnValue(mockStrategy);
|
|
91
|
-
// Llama al método a probar
|
|
92
|
-
const result = signer.verifySignature("data", "sig", "key");
|
|
93
|
-
// Verifica que el resultado sea false
|
|
94
|
-
expect(result).toBe(false);
|
|
95
|
-
});
|
|
96
|
-
// Prueba el valor por defecto del algoritmo
|
|
97
|
-
test("usa 'HS256' como algoritmo por defecto si no se pasa parámetro", () => {
|
|
98
|
-
// Prepara la estrategia mock
|
|
99
|
-
const mockStrategy = { verify: jest.fn().mockReturnValue(true) };
|
|
100
|
-
factoryMock.create.mockReturnValue(mockStrategy);
|
|
101
|
-
// Llama al método sin especificar algoritmo
|
|
102
|
-
signer.verifySignature("abc.def", "sig", "key");
|
|
103
|
-
// Verifica que se usó el algoritmo por defecto
|
|
104
|
-
expect(factoryMock.create).toHaveBeenCalledWith("HS256");
|
|
105
|
-
// Asegura que la estrategia fue llamada una vez
|
|
106
|
-
expect(mockStrategy.verify).toHaveBeenCalledTimes(1);
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
// ────────────────────────────────────────────────────────────────
|
|
110
|
-
// integración mínima (sin mock) - opcional
|
|
111
|
-
// ────────────────────────────────────────────────────────────────
|
|
112
|
-
describe("integración mínima", () => {
|
|
113
|
-
// Prueba que JwtSigner crea una instancia real de SignatureStrategyFactory
|
|
114
|
-
test("crea internamente una instancia real de SignatureStrategyFactory", () => {
|
|
115
|
-
// Borra el historial de llamadas acumulado por el beforeEach del describe padre
|
|
116
|
-
jwt_1.SignatureStrategyFactory.mockClear();
|
|
117
|
-
// Crea una nueva instancia de JwtSigner
|
|
118
|
-
const localSigner = new token_1.JwtSigner(encoder);
|
|
119
|
-
// Verifica que se creó una instancia de JwtSigner y que la fábrica fue instanciada
|
|
120
|
-
expect(localSigner).toBeInstanceOf(token_1.JwtSigner);
|
|
121
|
-
// Asegura que el constructor de SignatureStrategyFactory fue llamado una vez
|
|
122
|
-
expect(jwt_1.SignatureStrategyFactory).toHaveBeenCalledTimes(1);
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const domain_1 = require("src/domain");
|
|
4
|
-
const token_1 = require("src/infrastructure/jwt/token");
|
|
5
|
-
// ───────────────────────────────────────────────────────────────────────────────
|
|
6
|
-
// Helpers: Base64URL encode/decode (solo para el fake encoder y payloads)
|
|
7
|
-
// ───────────────────────────────────────────────────────────────────────────────
|
|
8
|
-
const b64urlEncode = (utf8) => {
|
|
9
|
-
const b64 = Buffer.from(utf8, "utf8").toString("base64");
|
|
10
|
-
return b64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
|
|
11
|
-
};
|
|
12
|
-
const b64urlDecode = (b64url) => {
|
|
13
|
-
let base64 = b64url.replace(/-/g, "+").replace(/_/g, "/");
|
|
14
|
-
const pad = base64.length % 4;
|
|
15
|
-
if (pad)
|
|
16
|
-
base64 += "=".repeat(4 - pad);
|
|
17
|
-
return Buffer.from(base64, "base64").toString("utf8");
|
|
18
|
-
};
|
|
19
|
-
// Fake encoder mínimo que respeta la firma esperada
|
|
20
|
-
class FakeBase64UrlEncoder {
|
|
21
|
-
decode(input) {
|
|
22
|
-
return b64urlDecode(input);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
describe("JwtTokenParser", () => {
|
|
26
|
-
let parser;
|
|
27
|
-
beforeEach(() => {
|
|
28
|
-
parser = new token_1.JwtTokenParser(new FakeBase64UrlEncoder());
|
|
29
|
-
});
|
|
30
|
-
// ────────────────────────────────────────────────────────────────────────────
|
|
31
|
-
// extractParts
|
|
32
|
-
// ────────────────────────────────────────────────────────────────────────────
|
|
33
|
-
describe("extractParts", () => {
|
|
34
|
-
test("devuelve [header, payload, signature] con 3 segmentos", () => {
|
|
35
|
-
const token = "aaa.bbb.ccc";
|
|
36
|
-
expect(parser.extractParts(token)).toEqual(["aaa", "bbb", "ccc"]);
|
|
37
|
-
});
|
|
38
|
-
test("con puntos de más, retorna los 3 primeros segmentos", () => {
|
|
39
|
-
const token = "a.b.c.d.e";
|
|
40
|
-
expect(parser.extractParts(token)).toEqual(["a", "b", "c"]);
|
|
41
|
-
});
|
|
42
|
-
test("con menos de 3 segmentos, rellena con undefined", () => {
|
|
43
|
-
const token = "a.b";
|
|
44
|
-
const [h, p, s] = parser.extractParts(token);
|
|
45
|
-
expect(h).toBe("a");
|
|
46
|
-
expect(p).toBe("b");
|
|
47
|
-
expect(s).toBeUndefined(); // comportamiento actual del método
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
// ────────────────────────────────────────────────────────────────────────────
|
|
51
|
-
// parsePayload
|
|
52
|
-
// ────────────────────────────────────────────────────────────────────────────
|
|
53
|
-
describe("parsePayload", () => {
|
|
54
|
-
test("decodifica y parsea el payload a objeto (sin verificar firma/tiempos)", () => {
|
|
55
|
-
const payloadObj = { sub: "123", exp: 1700000000 };
|
|
56
|
-
const header = b64urlEncode(JSON.stringify({ alg: "HS256", typ: "JWT" }));
|
|
57
|
-
const payload = b64urlEncode(JSON.stringify(payloadObj));
|
|
58
|
-
const signature = "signaturePartNoCheck";
|
|
59
|
-
const token = `${header}.${payload}.${signature}`;
|
|
60
|
-
const result = parser.parsePayload(token);
|
|
61
|
-
expect(result).toEqual(payloadObj);
|
|
62
|
-
});
|
|
63
|
-
test("si el payload no es JSON válido, lanza (propaga error de JSON.parse)", () => {
|
|
64
|
-
// payloadPart inválido (decodifica a texto no-JSON)
|
|
65
|
-
const header = "aaa";
|
|
66
|
-
const payload = b64urlEncode("not-a-json");
|
|
67
|
-
const signature = "ccc";
|
|
68
|
-
const token = `${header}.${payload}.${signature}`;
|
|
69
|
-
expect(() => parser.parsePayload(token)).toThrow(SyntaxError);
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
// ────────────────────────────────────────────────────────────────────────────
|
|
73
|
-
// parseAndValidatePayload
|
|
74
|
-
// ────────────────────────────────────────────────────────────────────────────
|
|
75
|
-
describe("parseAndValidatePayload", () => {
|
|
76
|
-
test("retorna objeto para payload válido", () => {
|
|
77
|
-
const payloadObj = { userId: "u1", roles: ["admin"] };
|
|
78
|
-
const payloadPart = b64urlEncode(JSON.stringify(payloadObj));
|
|
79
|
-
const result = parser.parseAndValidatePayload(payloadPart);
|
|
80
|
-
expect(result).toEqual(payloadObj);
|
|
81
|
-
});
|
|
82
|
-
test("si el encoding/JSON es inválido, lanza InvalidTokenFormatError (mensaje: Invalid token payload encoding)", () => {
|
|
83
|
-
// Usamos un fragmento que al decodificar no produce JSON válido
|
|
84
|
-
const payloadPart = b64urlEncode("not-json-here");
|
|
85
|
-
expect(() => parser.parseAndValidatePayload(payloadPart)).toThrow(domain_1.InvalidTokenFormatError);
|
|
86
|
-
expect(() => parser.parseAndValidatePayload(payloadPart)).toThrow(/invalid token payload encoding/i);
|
|
87
|
-
});
|
|
88
|
-
test('si el payload es string ("hola"), lanza InvalidTokenFormatError (must be an object)', () => {
|
|
89
|
-
const payloadPart = b64urlEncode(JSON.stringify("hola"));
|
|
90
|
-
expect(() => parser.parseAndValidatePayload(payloadPart)).toThrow(/payload must be an object/i);
|
|
91
|
-
});
|
|
92
|
-
test("si el payload es número (123), lanza InvalidTokenFormatError", () => {
|
|
93
|
-
const payloadPart = b64urlEncode(JSON.stringify(123));
|
|
94
|
-
expect(() => parser.parseAndValidatePayload(payloadPart)).toThrow(/payload must be an object/i);
|
|
95
|
-
});
|
|
96
|
-
test("si el payload es array ([]), lanza InvalidTokenFormatError", () => {
|
|
97
|
-
const payloadPart = b64urlEncode(JSON.stringify([]));
|
|
98
|
-
expect(() => parser.parseAndValidatePayload(payloadPart)).toThrow(/payload must be an object/i);
|
|
99
|
-
});
|
|
100
|
-
test("si el payload es null, lanza InvalidTokenFormatError", () => {
|
|
101
|
-
const payloadPart = b64urlEncode("null");
|
|
102
|
-
expect(() => parser.parseAndValidatePayload(payloadPart)).toThrow(/payload must be an object/i);
|
|
103
|
-
});
|
|
104
|
-
test("llama al encoder.decode con el payloadPart recibido", () => {
|
|
105
|
-
const spyDecode = jest.spyOn(FakeBase64UrlEncoder.prototype, "decode");
|
|
106
|
-
const obj = { a: 1 };
|
|
107
|
-
const payloadPart = b64urlEncode(JSON.stringify(obj));
|
|
108
|
-
const localParser = new token_1.JwtTokenParser(new FakeBase64UrlEncoder());
|
|
109
|
-
const result = localParser.parseAndValidatePayload(payloadPart);
|
|
110
|
-
expect(result).toEqual(obj);
|
|
111
|
-
expect(spyDecode).toHaveBeenCalledTimes(1);
|
|
112
|
-
expect(spyDecode).toHaveBeenCalledWith(payloadPart);
|
|
113
|
-
spyDecode.mockRestore();
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
// tests/infrastructure/jwt/token/jwt-token-validator.spec.ts
|
|
4
|
-
const errors_1 = require("src/domain/errors");
|
|
5
|
-
const token_1 = require("src/infrastructure/jwt/token");
|
|
6
|
-
describe("JwtTokenValidator.validateTokenInput", () => {
|
|
7
|
-
let validator;
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
validator = new token_1.JwtTokenValidator();
|
|
10
|
-
});
|
|
11
|
-
const expectInvalid = (token, message) => {
|
|
12
|
-
const act = () => validator.validateTokenInput(token);
|
|
13
|
-
expect(act).toThrow(errors_1.InvalidTokenFormatError);
|
|
14
|
-
if (message)
|
|
15
|
-
expect(act).toThrow(message);
|
|
16
|
-
};
|
|
17
|
-
// Casos válidos
|
|
18
|
-
describe("casos válidos", () => {
|
|
19
|
-
test("acepta un JWT bien formado (Base64URL, 3 segmentos, 2 puntos)", () => {
|
|
20
|
-
const validJwt = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0In0.dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk";
|
|
21
|
-
expect(() => validator.validateTokenInput(validJwt)).not.toThrow();
|
|
22
|
-
});
|
|
23
|
-
test("acepta tokens largos con guiones y guiones bajos válidos", () => {
|
|
24
|
-
const validJwt = "abc_DEF-123.ghi_JKL-456.mno_PQR-789xyz";
|
|
25
|
-
expect(() => validator.validateTokenInput(validJwt)).not.toThrow();
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
// Casos inválidos básicos
|
|
29
|
-
describe("validateBasicFormat", () => {
|
|
30
|
-
test("lanza si token es null", () => {
|
|
31
|
-
expectInvalid(null, /cannot be null or undefined/i);
|
|
32
|
-
});
|
|
33
|
-
test("lanza si token es undefined", () => {
|
|
34
|
-
expectInvalid(undefined, /cannot be null or undefined/i);
|
|
35
|
-
});
|
|
36
|
-
test("lanza si token no es string (number)", () => {
|
|
37
|
-
expectInvalid(123, /Token must be a string/i);
|
|
38
|
-
});
|
|
39
|
-
test("lanza si token no es string (objeto)", () => {
|
|
40
|
-
expectInvalid({}, /Token must be a string/i);
|
|
41
|
-
});
|
|
42
|
-
test("lanza si cadena está vacía", () => {
|
|
43
|
-
expectInvalid("", /cannot be empty/i);
|
|
44
|
-
});
|
|
45
|
-
test("lanza si solo contiene espacios", () => {
|
|
46
|
-
expectInvalid(" ", /only whitespace/i);
|
|
47
|
-
});
|
|
48
|
-
test("lanza si tiene espacios al inicio o final", () => {
|
|
49
|
-
expectInvalid(" abc.def.ghi ", /leading or trailing whitespace/i);
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
// Casos inválidos de estructura JWT
|
|
53
|
-
describe("validateJwtStructure", () => {
|
|
54
|
-
test("lanza si longitud < 10", () => {
|
|
55
|
-
expectInvalid("a.b.c", /too short/i);
|
|
56
|
-
});
|
|
57
|
-
test("lanza si no tiene puntos", () => {
|
|
58
|
-
expectInvalid("abcdefghijk", /expected 2 dots, found 0/i);
|
|
59
|
-
});
|
|
60
|
-
test("lanza si tiene solo 1 punto", () => {
|
|
61
|
-
expectInvalid("abcdefghij.klmnop", /expected 2 dots, found 1/i);
|
|
62
|
-
});
|
|
63
|
-
test("lanza si tiene más de 2 puntos", () => {
|
|
64
|
-
expectInvalid("abcd.efgh.ijkl.mnop", /expected 2 dots, found 3/i);
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
// Casos inválidos de caracteres Base64URL
|
|
68
|
-
describe("validateCharacters (Base64URL)", () => {
|
|
69
|
-
test("lanza si contiene '+'", () => {
|
|
70
|
-
expectInvalid("abcde+123.fghi_JKL.mnop-QR", /invalid characters/i);
|
|
71
|
-
});
|
|
72
|
-
test("lanza si contiene '/'", () => {
|
|
73
|
-
expectInvalid("abcde/123.fghi_JKL.mnop-QR", /invalid characters/i);
|
|
74
|
-
});
|
|
75
|
-
test("lanza si contiene '=' (padding)", () => {
|
|
76
|
-
expectInvalid("abcde=123.fghi_JKL.mnop-QR", /invalid characters/i);
|
|
77
|
-
});
|
|
78
|
-
test("lanza si algún segmento está vacío (..)", () => {
|
|
79
|
-
expectInvalid("abcde..klmnopqr", /invalid characters/i);
|
|
80
|
-
});
|
|
81
|
-
test("lanza si hay espacios internos", () => {
|
|
82
|
-
expectInvalid("abcde .fghi_JKL.mnop-QR", /invalid characters/i);
|
|
83
|
-
});
|
|
84
|
-
test("lanza si hay caracteres fuera del alfabeto Base64URL", () => {
|
|
85
|
-
expectInvalid("abcde%.fghi_JKL.mnop-QR", /invalid characters/i);
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const jwt_1 = require("src/infrastructure/jwt");
|
|
4
|
-
const token_1 = require("src/infrastructure/jwt/token");
|
|
5
|
-
const shared_1 = require("src/shared");
|
|
6
|
-
// ────────────────────────────────────────────────────────────────
|
|
7
|
-
// Mock de SignatureStrategyFactory y su comportamiento
|
|
8
|
-
// ────────────────────────────────────────────────────────────────
|
|
9
|
-
jest.mock("src/infrastructure/jwt/factory");
|
|
10
|
-
describe("JwtSigner", () => {
|
|
11
|
-
// Variables comunes para las pruebas
|
|
12
|
-
let signer;
|
|
13
|
-
let factoryMock;
|
|
14
|
-
let encoder;
|
|
15
|
-
const algorithm = "HS256";
|
|
16
|
-
// ────────────────────────────────────────────────────────────────
|
|
17
|
-
// Configuración antes de cada prueba
|
|
18
|
-
// ────────────────────────────────────────────────────────────────
|
|
19
|
-
beforeEach(() => {
|
|
20
|
-
// Instancia real del codificador
|
|
21
|
-
encoder = new shared_1.Base64UrlEncoder();
|
|
22
|
-
// Mock de factory.create() → devuelve una estrategia con sign/verify falsos
|
|
23
|
-
factoryMock = {
|
|
24
|
-
create: jest.fn(),
|
|
25
|
-
};
|
|
26
|
-
// Forzar el constructor de SignatureStrategyFactory para devolver nuestro mock
|
|
27
|
-
jwt_1.SignatureStrategyFactory.mockImplementation(() => factoryMock);
|
|
28
|
-
// Crea la instancia de JwtSigner que vamos a probar
|
|
29
|
-
signer = new token_1.JwtSigner(encoder);
|
|
30
|
-
});
|
|
31
|
-
// Limpia los mocks después de cada prueba
|
|
32
|
-
afterEach(() => {
|
|
33
|
-
jest.clearAllMocks();
|
|
34
|
-
});
|
|
35
|
-
// ────────────────────────────────────────────────────────────────
|
|
36
|
-
// sign()
|
|
37
|
-
// ────────────────────────────────────────────────────────────────
|
|
38
|
-
describe("sign", () => {
|
|
39
|
-
// Prueba básica de firma
|
|
40
|
-
test("firma datos usando la estrategia devuelta por la fábrica", () => {
|
|
41
|
-
// Prepara la estrategia mock
|
|
42
|
-
const fakeSignature = "signed-data";
|
|
43
|
-
const mockStrategy = { sign: jest.fn().mockReturnValue(fakeSignature) };
|
|
44
|
-
factoryMock.create.mockReturnValue(mockStrategy);
|
|
45
|
-
// Llama al método a probar
|
|
46
|
-
const result = signer.sign("header.payload", "secret-key", "HS256");
|
|
47
|
-
// Verificaciones
|
|
48
|
-
// Asegura que la fábrica fue llamada con el algoritmo correcto
|
|
49
|
-
expect(factoryMock.create).toHaveBeenCalledWith("HS256");
|
|
50
|
-
// Asegura que la estrategia firmó los datos correctamente
|
|
51
|
-
expect(mockStrategy.sign).toHaveBeenCalledWith("header.payload", "secret-key");
|
|
52
|
-
// Asegura que el resultado es el esperado
|
|
53
|
-
expect(result).toBe(fakeSignature);
|
|
54
|
-
});
|
|
55
|
-
// Prueba el valor por defecto del algoritmo
|
|
56
|
-
test("usa 'HS256' como algoritmo por defecto si no se especifica", () => {
|
|
57
|
-
// Prepara la estrategia mock
|
|
58
|
-
const mockStrategy = { sign: jest.fn().mockReturnValue("sig") };
|
|
59
|
-
factoryMock.create.mockReturnValue(mockStrategy);
|
|
60
|
-
// Llama al método sin especificar algoritmo
|
|
61
|
-
signer.sign("abc.def", "key", algorithm);
|
|
62
|
-
// Verifica que se usó el algoritmo por defecto
|
|
63
|
-
expect(factoryMock.create).toHaveBeenCalledWith("HS256");
|
|
64
|
-
// Asegura que la estrategia fue llamada una vez
|
|
65
|
-
expect(mockStrategy.sign).toHaveBeenCalledTimes(1);
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
// ────────────────────────────────────────────────────────────────
|
|
69
|
-
// verifySignature()
|
|
70
|
-
// ────────────────────────────────────────────────────────────────
|
|
71
|
-
describe("verifySignature", () => {
|
|
72
|
-
// Prueba básica de verificación
|
|
73
|
-
test("verifica correctamente usando la estrategia devuelta por la fábrica", () => {
|
|
74
|
-
// Prepara la estrategia mock
|
|
75
|
-
const mockStrategy = { verify: jest.fn().mockReturnValue(true) };
|
|
76
|
-
factoryMock.create.mockReturnValue(mockStrategy);
|
|
77
|
-
// Llama al método a probar
|
|
78
|
-
const result = signer.verifySignature("header.payload", "signature", "secret", "HS512");
|
|
79
|
-
// Verificaciones
|
|
80
|
-
// Asegura que la fábrica fue llamada con el algoritmo correcto
|
|
81
|
-
expect(factoryMock.create).toHaveBeenCalledWith("HS512");
|
|
82
|
-
// Asegura que la estrategia verificó los datos correctamente
|
|
83
|
-
expect(mockStrategy.verify).toHaveBeenCalledWith("header.payload", "signature", "secret");
|
|
84
|
-
// Asegura que el resultado es el esperado
|
|
85
|
-
expect(result).toBe(true);
|
|
86
|
-
});
|
|
87
|
-
// Prueba cuando la verificación falla
|
|
88
|
-
test("retorna false si verify devuelve false", () => {
|
|
89
|
-
// Prepara la estrategia mock
|
|
90
|
-
const mockStrategy = { verify: jest.fn().mockReturnValue(false) };
|
|
91
|
-
factoryMock.create.mockReturnValue(mockStrategy);
|
|
92
|
-
// Llama al método a probar
|
|
93
|
-
const result = signer.verifySignature("data", "sig", "key", algorithm);
|
|
94
|
-
// Verifica que el resultado sea false
|
|
95
|
-
expect(result).toBe(false);
|
|
96
|
-
});
|
|
97
|
-
// Prueba el valor por defecto del algoritmo
|
|
98
|
-
test("usa 'HS256' como algoritmo por defecto si no se pasa parámetro", () => {
|
|
99
|
-
// Prepara la estrategia mock
|
|
100
|
-
const mockStrategy = { verify: jest.fn().mockReturnValue(true) };
|
|
101
|
-
factoryMock.create.mockReturnValue(mockStrategy);
|
|
102
|
-
// Llama al método sin especificar algoritmo
|
|
103
|
-
signer.verifySignature("abc.def", "sig", "key", algorithm);
|
|
104
|
-
// Verifica que se usó el algoritmo por defecto
|
|
105
|
-
expect(factoryMock.create).toHaveBeenCalledWith("HS256");
|
|
106
|
-
// Asegura que la estrategia fue llamada una vez
|
|
107
|
-
expect(mockStrategy.verify).toHaveBeenCalledTimes(1);
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
// ────────────────────────────────────────────────────────────────
|
|
111
|
-
// integración mínima (sin mock) - opcional
|
|
112
|
-
// ────────────────────────────────────────────────────────────────
|
|
113
|
-
describe("integración mínima", () => {
|
|
114
|
-
// Prueba que JwtSigner crea una instancia real de SignatureStrategyFactory
|
|
115
|
-
test("crea internamente una instancia real de SignatureStrategyFactory", () => {
|
|
116
|
-
// Borra el historial de llamadas acumulado por el beforeEach del describe padre
|
|
117
|
-
jwt_1.SignatureStrategyFactory.mockClear();
|
|
118
|
-
// Crea una nueva instancia de JwtSigner
|
|
119
|
-
const localSigner = new token_1.JwtSigner(encoder);
|
|
120
|
-
// Verifica que se creó una instancia de JwtSigner y que la fábrica fue instanciada
|
|
121
|
-
expect(localSigner).toBeInstanceOf(token_1.JwtSigner);
|
|
122
|
-
// Asegura que el constructor de SignatureStrategyFactory fue llamado una vez
|
|
123
|
-
expect(jwt_1.SignatureStrategyFactory).toHaveBeenCalledTimes(1);
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|