Skip to content

Commit

Permalink
Add /v1alpha2/validate-creds (#752)
Browse files Browse the repository at this point in the history
Signed-off-by: munishchouhan <[email protected]>
  • Loading branch information
munishchouhan authored Nov 20, 2024
1 parent 080d5cc commit e24ec62
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package io.seqera.wave.controller

import io.micronaut.http.annotation.Body
import io.micronaut.http.annotation.Controller
import io.micronaut.http.annotation.Post
import io.micronaut.scheduling.TaskExecutors
Expand All @@ -26,15 +27,21 @@ import io.seqera.wave.auth.RegistryAuthService
import jakarta.inject.Inject
import jakarta.validation.Valid

@Controller("/validate-creds")
@Controller("/")
@ExecuteOn(TaskExecutors.BLOCKING)
class ValidateController {

@Inject RegistryAuthService loginService

@Post
@Deprecated
@Post("/validate-creds")
Boolean validateCreds(@Valid ValidateRegistryCredsRequest request){
loginService.validateUser(request.registry, request.userName, request.password)
}

@Post("/v1alpha2/validate-creds")
Boolean validateCredsV2(@Valid @Body ValidateRegistryCredsRequest request){
loginService.validateUser(request.registry, request.userName, request.password)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,67 @@ class ValidateCredsControllerTest extends Specification implements SecureDockerR
'nope' | 'yepes' | "https://quay.io" | false
'test' | 'test' | 'test' | true
}

void 'should validate username required'() {
when:
HttpRequest request = HttpRequest.POST("/v1alpha2/validate-creds", [
password: 'test',
])
client.toBlocking().exchange(request, Boolean)
then:
def e = thrown(HttpClientResponseException)
}

void 'should validate pwd required'() {
when:
HttpRequest request = HttpRequest.POST("/v1alpha2/validate-creds", [
userName: 'test',
])
client.toBlocking().exchange(request, Boolean)
then:
def e = thrown(HttpClientResponseException)
}

void 'should validate the test user'() {
given:
def req = [
userName:'test',
password:'test',
registry: getTestRegistryUrl('test') ]
and:
HttpRequest request = HttpRequest.POST("/v1alpha2/validate-creds", req)
when:
HttpResponse<Boolean> response = client.toBlocking().exchange(request, Boolean)
then:
response.status() == HttpStatus.OK
and:
response.body()
}

void 'test validateController valid login'() {
given:
def req = [
userName: USER,
password: PWD,
registry: getTestRegistryUrl(REGISTRY_URL)
]
HttpRequest request = HttpRequest.POST("/v1alpha2/validate-creds", req)
when:
HttpResponse<Boolean> response = client.toBlocking().exchange(request, Boolean)

then:
response.status() == HttpStatus.OK
and:
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
}
}

0 comments on commit e24ec62

Please sign in to comment.