Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add SubdomainTenantResolver tests #232

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ package io.micronaut.multitenancy.tenantresolver

import io.micronaut.context.ApplicationContext
import io.micronaut.context.env.Environment
import io.micronaut.http.HttpHeaders
import io.micronaut.http.HttpRequest
import io.micronaut.multitenancy.exceptions.TenantNotFoundException
import spock.lang.AutoCleanup
import spock.lang.PendingFeature
import spock.lang.Shared
import spock.lang.Specification

Expand All @@ -41,4 +45,71 @@ class SubdomainTenantResolverEnabledSpec extends Specification {
context.containsBean(HttpRequestTenantResolver)
context.getBean(HttpRequestTenantResolver) instanceof SubdomainTenantResolver
}

@PendingFeature
void "TenantResolver resolves tenant identifier without host header"() {
given:
HttpRequest<?> request = HttpRequest.GET(uri)

expect:
context.getBean(SubdomainTenantResolver).resolveTenantIdentifier(request) == expected

and:
new SubdomainTenantResolver().resolveTenantIdentifier(request) == expected

where:
uri | expected
'https://example.com/path/resource' | 'DEFAULT'
'https://www.example.com/path/resource' | 'www'
'https://domain.co.uk/path/resource' | 'DEFAULT'
'https://duper.domain.co.uk/path/resource' | 'duper'
'https://super.duper.domain.co.uk/path/resource' | 'super.duper'
'https://example.com/path/resource' | 'DEFAULT'
}

void "TenantResolver resolves tenant identifier"(String uri, String header, String expected) {
given:
HttpRequest<?> request = HttpRequest.GET(uri).header(HttpHeaders.HOST, header)

expect:
context.getBean(SubdomainTenantResolver).resolveTenantIdentifier(request) == expected

and:
new SubdomainTenantResolver().resolveTenantIdentifier(request) == expected

where:
uri | header | expected
'https://www.example.com/path/resource' | '' | 'DEFAULT'
'https://www.example.com/path/resource' | 'test' | 'DEFAULT'
'https://example.com/path/resource' | 'www.test.com' | 'www'
'https://example.com/path/resource' | 'duper.domain.co.uk' | 'duper'
'https://example.com/path/resource' | 'lorem.ipsum.dev' | 'lorem'
}

@PendingFeature
void "TenantResolver resolves tenant identifier with header"(String uri, String header, String expected) {
given:
HttpRequest<?> request = HttpRequest.GET(uri).header(HttpHeaders.HOST, header)

expect:
context.getBean(SubdomainTenantResolver).resolveTenantIdentifier(request) == expected

and:
new SubdomainTenantResolver().resolveTenantIdentifier(request) == expected

where:
uri | header | expected
'https://www.example.com/path/resource' | 'test.com' | 'DEFAULT'
'https://www.example.com/path/resource' | 'test.com' | 'DEFAULT'
'https://example.com/path/resource' | 'domain.co.uk' | 'DEFAULT'
'https://example.com/path/resource' | 'super.duper.domain.co.uk' | 'super.duper'
}

void "TenantResolver resolves tenant identifier - no http request"() {
when:
new SubdomainTenantResolver().resolveTenantIdentifier()

then:
thrown(TenantNotFoundException)
}
}