From dc828a0dabeeca2653e18bd89552ab817d02950f Mon Sep 17 00:00:00 2001 From: Michael Avoyan Date: Mon, 25 Dec 2023 12:15:24 +0200 Subject: [PATCH] token expires in property --- VCL/build.gradle | 4 +-- .../api/entities/VCLToken.kt | 25 ++++++++++++-- .../entities/VCLSubmissionTest.kt | 3 ++ .../entities/VCLTokenTest.kt | 33 +++++++++++++++++++ .../resources/valid/TokenMocks.kt | 17 ++++++++++ 5 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 VCL/src/test/java/io/velocitycareerlabs/entities/VCLTokenTest.kt create mode 100644 VCL/src/test/java/io/velocitycareerlabs/infrastructure/resources/valid/TokenMocks.kt diff --git a/VCL/build.gradle b/VCL/build.gradle index 0e2970d0..2656fe8b 100644 --- a/VCL/build.gradle +++ b/VCL/build.gradle @@ -13,8 +13,8 @@ android { defaultConfig { minSdk 24 targetSdk 33 - versionName "1.21.5" - versionCode 117 + versionName "1.22.0" + versionCode 118 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles "consumer-rules.pro" } diff --git a/VCL/src/main/java/io/velocitycareerlabs/api/entities/VCLToken.kt b/VCL/src/main/java/io/velocitycareerlabs/api/entities/VCLToken.kt index 38c52cae..38b663fc 100644 --- a/VCL/src/main/java/io/velocitycareerlabs/api/entities/VCLToken.kt +++ b/VCL/src/main/java/io/velocitycareerlabs/api/entities/VCLToken.kt @@ -4,7 +4,28 @@ * Copyright 2022 Velocity Career Labs inc. * SPDX-License-Identifier: Apache-2.0 */ - package io.velocitycareerlabs.api.entities -data class VCLToken(val value: String) \ No newline at end of file +data class VCLToken( + /** + * token value represented as jwt string + */ + val value: String +) { + /** + * token value represented as VCLJwt object + */ + val jwtValue = VCLJwt(value) + + constructor(jwtValue: VCLJwt) : this(jwtValue.encodedJwt ?: "") + + /** + * token expiration period in milliseconds + */ + val expiresIn: Long? + get() = jwtValue.signedJwt?.payload?.toJSONObject()?.get(CodingKeys.KeyExp) as? Long + + companion object CodingKeys { + const val KeyExp = "exp" + } +} \ No newline at end of file diff --git a/VCL/src/test/java/io/velocitycareerlabs/entities/VCLSubmissionTest.kt b/VCL/src/test/java/io/velocitycareerlabs/entities/VCLSubmissionTest.kt index aa12eac5..f50b6491 100644 --- a/VCL/src/test/java/io/velocitycareerlabs/entities/VCLSubmissionTest.kt +++ b/VCL/src/test/java/io/velocitycareerlabs/entities/VCLSubmissionTest.kt @@ -1,5 +1,8 @@ /** * Created by Michael Avoyan on 11/12/2022. + * + * Copyright 2022 Velocity Career Labs inc. + * SPDX-License-Identifier: Apache-2.0 */ package io.velocitycareerlabs.entities diff --git a/VCL/src/test/java/io/velocitycareerlabs/entities/VCLTokenTest.kt b/VCL/src/test/java/io/velocitycareerlabs/entities/VCLTokenTest.kt new file mode 100644 index 00000000..09fd70e7 --- /dev/null +++ b/VCL/src/test/java/io/velocitycareerlabs/entities/VCLTokenTest.kt @@ -0,0 +1,33 @@ +/** + * Created by Michael Avoyan on 24/12/2023. + * + * Copyright 2022 Velocity Career Labs inc. + * SPDX-License-Identifier: Apache-2.0 + */ +package io.velocitycareerlabs.entities + +import io.velocitycareerlabs.api.entities.VCLToken +import io.velocitycareerlabs.infrastructure.resources.valid.TokenMocks +import org.junit.Test + +class VCLTokenTest { + lateinit var subject: VCLToken + + @Test + fun testToken1() { + subject = VCLToken(value = TokenMocks.TokenStr) + + assert(subject.value == TokenMocks.TokenStr) + assert(subject.jwtValue.encodedJwt == TokenMocks.TokenStr) + assert(subject.expiresIn == 1704020514L) + } + + @Test + fun testToken2() { + subject = VCLToken(jwtValue = TokenMocks.TokenJwt) + + assert(subject.value == TokenMocks.TokenJwt.encodedJwt) + assert(subject.jwtValue.encodedJwt == TokenMocks.TokenJwt.encodedJwt) + assert(subject.expiresIn == 1704020514L) + } +} \ No newline at end of file diff --git a/VCL/src/test/java/io/velocitycareerlabs/infrastructure/resources/valid/TokenMocks.kt b/VCL/src/test/java/io/velocitycareerlabs/infrastructure/resources/valid/TokenMocks.kt new file mode 100644 index 00000000..e8a2233c --- /dev/null +++ b/VCL/src/test/java/io/velocitycareerlabs/infrastructure/resources/valid/TokenMocks.kt @@ -0,0 +1,17 @@ +/** + * Created by Michael Avoyan on 24/12/2023. + * + * Copyright 2022 Velocity Career Labs inc. + * SPDX-License-Identifier: Apache-2.0 + */ +package io.velocitycareerlabs.infrastructure.resources.valid + +import io.velocitycareerlabs.api.entities.VCLJwt + +class TokenMocks { + companion object { + const val TokenStr = + "eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NksifQ.eyJqdGkiOiI2NTg4MGY5ZThkMjY3NWE0NTBhZDVhYjgiLCJpc3MiOiJkaWQ6aW9uOkVpQXBNTGRNYjROUGI4c2FlOS1oWEdIUDc5VzFnaXNBcFZTRTgwVVNQRWJ0SkEiLCJhdWQiOiJkaWQ6aW9uOkVpQXBNTGRNYjROUGI4c2FlOS1oWEdIUDc5VzFnaXNBcFZTRTgwVVNQRWJ0SkEiLCJleHAiOjE3MDQwMjA1MTQsInN1YiI6IjYzODZmODI0ZTc3NDc4OWM0MDNjOTZhMCIsImlhdCI6MTcwMzQxNTcxNH0.AJwKvQ_YNviFTjcuoJUR7ZHFEIbKY9zLCJv4DfC_PPk3Q-15rwKucYy8GdlfKnHLioBA5X37lpG-js8EztEKDg" + val TokenJwt = VCLJwt(encodedJwt = TokenMocks.TokenStr) + } +} \ No newline at end of file