Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
quentinovega committed Sep 16, 2024
1 parent 3dcfb9a commit 543a792
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 0 deletions.
8 changes: 8 additions & 0 deletions daikoku/app/domain/SchemaDefinition.scala
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,14 @@ object SchemaDefinition {
ApiKeyRestrictionsType,
resolve = _.value.restrictions
)
),
ReplaceField(
"validUntil",
Field(
"validUntil",
OptionType(DateTimeUnitype),
resolve = _.value.validUntil
)
)
)

Expand Down
116 changes: 116 additions & 0 deletions daikoku/test/daikoku/ApiControllerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1712,6 +1712,122 @@ class ApiControllerSpec()

respOrg.status mustBe 200
}

"setup validUntil date for a subscription to his api" in {
val parentPlan = FreeWithoutQuotas(
id = UsagePlanId("parent.dev"),
tenant = tenant.id,
billingDuration = BillingDuration(1, BillingTimeUnit.Month),
currency = Currency("EUR"),
customName = None,
customDescription = None,
otoroshiTarget = Some(
OtoroshiTarget(
containerizedOtoroshi,
Some(
AuthorizedEntities(
routes = Set(OtoroshiRouteId(parentRouteId))
)
)
)
),
allowMultipleKeys = Some(false),
subscriptionProcess = Seq.empty,
integrationProcess = IntegrationProcess.ApiKey,
autoRotation = Some(false),
aggregationApiKeysSecurity = Some(true)
)

val parentApi = defaultApi.api.copy(
id = ApiId("parent-id"),
name = "parent API",
team = teamOwnerId,
possibleUsagePlans = Seq(UsagePlanId("parent.dev")),
defaultUsagePlan = UsagePlanId("parent.dev").some
)

val parentSub = ApiSubscription(
id = ApiSubscriptionId("parent_sub"),
tenant = tenant.id,
apiKey = parentApiKey,
plan = parentPlan.id,
createdAt = DateTime.now(),
team = teamConsumerId,
api = parentApi.id,
by = userTeamAdminId,
customName = None,
rotation = None,
integrationToken = "parent_token"
)

setupEnvBlocking(
tenants = Seq(
tenant.copy(
aggregationApiKeysSecurity = Some(true),
otoroshiSettings = Set(
OtoroshiSettings(
id = containerizedOtoroshi,
url =
s"http://otoroshi.oto.tools:${container.mappedPort(8080)}",
host = "otoroshi-api.oto.tools",
clientSecret = otoroshiAdminApiKey.clientSecret,
clientId = otoroshiAdminApiKey.clientId
)
)
)
),
users = Seq(userAdmin),
teams = Seq(teamOwner, teamConsumer, defaultAdminTeam),
usagePlans = Seq(parentPlan, adminApiPlan),
apis = Seq(parentApi, adminApi),
subscriptions = Seq(parentSub))

val session = loginWithBlocking(userAdmin, tenant)
//check validnuntil dans oto
val respPreOto = httpJsonCallBlocking(
path = s"/api/apikeys/${parentSub.apiKey.clientId}",
baseUrl = "http://otoroshi-api.oto.tools",
headers = Map(
"Otoroshi-Client-Id" -> otoroshiAdminApiKey.clientId,
"Otoroshi-Client-Secret" -> otoroshiAdminApiKey.clientSecret,
"Host" -> "otoroshi-api.oto.tools"
),
port = container.mappedPort(8080)
)(tenant, session)

(respPreOto.json \ "validUntil").asOpt[Boolean] mustBe None



//update subscription
val validUntil = DateTime.now().plusHours(1)
val respUpdate = httpJsonCallBlocking(
path = s"/api/teams/${teamOwnerId.value}/subscriptions/${parentSub.id.value}",
method = "PUT",
body = Some(
parentSub
.copy(
validUntil = validUntil.some
)
.asSafeJson
)
)(tenant, session)
respUpdate.status mustBe 200

//check validUntil dans oto
val respUpdateOto = httpJsonCallBlocking(
path = s"/api/apikeys/${parentSub.apiKey.clientId}",
baseUrl = "http://otoroshi-api.oto.tools",
headers = Map(
"Otoroshi-Client-Id" -> otoroshiAdminApiKey.clientId,
"Otoroshi-Client-Secret" -> otoroshiAdminApiKey.clientSecret,
"Host" -> "otoroshi-api.oto.tools"
),
port = container.mappedPort(8080)
)(tenant, session)
(respUpdateOto.json \ "validUntil").asOpt[Long] mustBe validUntil.getMillis
)
}
}

"a api editor" can {
Expand Down

0 comments on commit 543a792

Please sign in to comment.