Skip to content

Commit

Permalink
wip4
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Di Tommaso <[email protected]>
  • Loading branch information
pditommaso committed Dec 21, 2023
1 parent 57a1d08 commit c59f5d8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class RegistryAuthServiceTest extends Specification implements SecureDockerRegis
void 'test valid login'() {
given:

String uri = getTestRegistryUrl(REGISTRY)
String uri = getTestRegistryName(REGISTRY)

when:
boolean logged = loginService.login(uri, USER, PWD)
Expand Down Expand Up @@ -119,10 +119,10 @@ class RegistryAuthServiceTest extends Specification implements SecureDockerRegis

void 'test containerService valid login'() {
given:
String uri = getTestRegistryUrl(REGISTRY)
String registry = getTestRegistryName(REGISTRY)

when:
boolean logged = loginService.validateUser(uri, USER, PWD)
boolean logged = loginService.validateUser(registry, USER, PWD)

then:
logged == VALID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class ValidateCredsControllerTest extends Specification implements SecureDockerR
def req = [
userName:'test',
password:'test',
registry: getTestRegistryUrl('test') ]
registry: getTestRegistryName('test') ]
and:
HttpRequest request = HttpRequest.POST("/validate-creds", req)
when:
Expand All @@ -106,7 +106,7 @@ class ValidateCredsControllerTest extends Specification implements SecureDockerR
def req = [
userName: USER,
password: PWD,
registry: getTestRegistryUrl(REGISTRY_URL)
registry: getTestRegistryName(REGISTRY)
]
HttpRequest request = HttpRequest.POST("/validate-creds", req)
when:
Expand All @@ -118,13 +118,13 @@ class ValidateCredsControllerTest extends Specification implements SecureDockerR
response.body() == VALID

where:
USER | PWD | REGISTRY_URL | VALID
'test' | 'test' | 'test' | true
'nope' | 'yepes' | 'test' | false
dockerUsername | dockerPassword | "https://registry-1.docker.io" | true
'nope' | 'yepes' | "https://registry-1.docker.io" | false
quayUsername | quayPassword | "https://quay.io" | true
'nope' | 'yepes' | "https://quay.io" | false
'test' | 'test' | 'test' | true
USER | PWD | REGISTRY | VALID
'test' | 'test' | 'test' | true
'nope' | 'yepes' | 'test' | false
dockerUsername | dockerPassword | "registry-1.docker.io" | true
'nope' | 'yepes' | "registry-1.docker.io" | false
quayUsername | quayPassword | "quay.io" | true
'nope' | 'yepes' | "quay.io" | false
'test' | 'test' | 'test' | true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ trait BaseTestContainerRegistry {

abstract GenericContainer getTestcontainers()

String getTestRegistryUrl(String registry=null) {
String getTestRegistryName(String registry=null) {
if( !registry || registry=='test' || registry=='localhost' ) {
int port = testcontainers.firstMappedPort
return "${testcontainers.getHost()}:$port"
Expand All @@ -40,6 +40,10 @@ trait BaseTestContainerRegistry {
return registry
}

String getTestRegistryUrl(String registry=null) {
return "http://" + getTestRegistryName(registry)
}

RegistryInfo getLocalTestRegistryInfo() {
final uri = new URI(getTestRegistryUrl())
new RegistryInfo('test', uri, new RegistryAuth(uri, null, RegistryAuth.Type.Basic))
Expand Down

0 comments on commit c59f5d8

Please sign in to comment.