Open yaravind opened 8 years ago
Could you please give me more details?
My real REST service forces a HTTP(S) Basic authentication (username/password) for all of its clients. I'd like to stub this behavior using MOCO while testing my clients. Reference: https://www.httpwatch.com/httpgallery/authentication/
@dreamhead can you please comment?
Why not put HTTP header directly?
I can add the header from client perspective. I am wondering how to fail the test if wrong credentials are passed?
400 will be returned if no credential is matched. You can also write a configuration for wrong credentials if you need a specific response.
Thanks. I got this working with HTTP. However, with HTTP(S) the following test is (in Groovy using Spock)
def "Supports Jenkins with SSL and Basic Authentication"() {
given: "Correct username and password"
//trust the self-signed cert.jks
setTrustStore("/cert.jks", "mocohttps")
def httpsServer = httpsServer(10443, HttpsCertificate.certificate(pathResource("cert.jks"), "mocohttps", "mocohttps"))
httpsServer.request(and(by(uri("/api/json")), by(header("Authorization", "Basic dXNlcjpwYXNzd29yZA=="))))
.response(pathResource("single-job.json"))
mock = runner(httpsServer)
mock.start()
def userName = "user"
def password = "password"
when:
def url = new URL("https://localhost:10443/api/json")
def jenkins = new JenkinsClient(url, userName, password)
def response = jenkins.get()
then: "A valid response should be present"
response.isPresent() == true
mock.stop()
}
the following error
groovy.lang.MissingMethodException: No signature of method: com.github.dreamhead.moco.action.MocoRequestAction.call() is applicable for argument types: (com.github.dreamhead.moco.handler.HeaderResponseHandler) values: [com.github.dreamhead.moco.handler.HeaderResponseHandler@4dd6fd0a]
Possible solutions: wait(), any(), wait(long), any(groovy.lang.Closure), each(groovy.lang.Closure), find()
at org.aravind.oss.jenkins.JenkinsClientTest.Supports Jenkins with SSL and Basic Authentication(JenkinsClientTest.groovy:152)
I believe it has something to do with telling the httpsServer to expect the "Authorization" header.
It seems you are using MocoRequestAction which should not be used here. But I'm not quite sure which line is the root cause.
facing the same issue here.
I need to stub basic authentication support. I am wondering how to test it?