开发者

Authentication problems between Groovy & CouchDB?

开发者 https://www.devze.com 2023-01-03 22:24 出处:网络
fairly new to Groovy and I\'ve been trying to write some test cases with Groovy for out REST interfaces. To setup our test fixture I needed to clearout the CouchDB databases and wrote a simple script

fairly new to Groovy and I've been trying to write some test cases with Groovy for out REST interfaces. To setup our test fixture I needed to clearout the CouchDB databases and wrote a simple script to do this, but for some reason I keep getting Unauthorized messages back from CouchDB. Reduced the code down and still can't see why even though the example script is so simple now. The CouchDB instance has the admin user setup, but that's the only deviation from the default setup. Checked the username/password several times. Annoyingly coping the request from the groovy log and adding 'curl -X ..' works from the cmd line.

@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.5.0') 
import groovyx.net.http.RESTClient 

RESTClient couchDBRestApi = new RESTClient('http://localhost:5984/') 
couchDBRestApi.auth.basic 'scott', 'tiger' 

['mydb'].each { name -> 
  def resp = couchDBRestApi.delete(path:name) 
  assert resp.status == 200 
}

Looking at the logs I'm worried about a couple of entries in particular the empty list at end of 'WARN DefaultRequestDirector - Authentication error: Unable to respond to any of these challenges: {}' ? and ' DEBUG RESTClient - Response code: 401; found handler: org.codehaus.groovy.runtime.MethodClosure@e2e4d7' ?

full log reads:

2010-06-14 15:19:27,520 DEBUG  RESTClient - DELETE http://localhost:5984/mydb
2010-06-14 15:19:27,522 DEBUG  wire -> "DELETE /mydb HTTP/1.1[EOL]" 
2010-06-14 15:19:27,523 DEBUG  wire -> "Accept: /[EOL]" 
2010-06-14 15:19:27,523 DEBUG  wire -> "Host: localhost:5984[EOL]" 
2010-06-14 15:19:27,524 DEBUG  wire -> "Connection: Keep-Alive[EOL]" 
2010-06-14 15:19:27,525 DEBUG  wire -> "User-Agent: Apache-HttpClient/4.0 (java 1.5)[EOL]" 
2010-06-14 15:19:27,525 DEBUG  wire -> "Accept-Encoding: gzip,deflate[EOL]" 
2010-06-14 15:19:27,526 DEBUG  wire -> "[EOL]" 
2010-06-14 15:19:27,526 DEBUG  headers -> DELETE /mydb HTTP/1.1 
2010-06-14 15:19:27,527 DEBUG  headers -> Accept: / 
2010-06-14 15:19:27,527 DEBUG  headers -> Host: localhost:5984 
2010-06-14 15:19:27,528 DEBUG  headers -> Connection: Keep-Alive 
2010-06-14 15:19:27,528 DEBUG  headers -> User-Agent: Apache-HttpClient/4.0 (java 1.5) 
2010-06-14 15:19:27,529 DEBUG  headers -> Accept-Encoding: gzip,deflate 
2010-06-14 15:19:27,543 DEBUG  wire <-  "HTTP/1.1 401 Unauthorized[EOL]" 
2010-06-14 15:19:27,543 DEBUG  wire <-  "Server: CouchDB/0.11.0 (Erlang OTP/R13B)[EOL]" 
2010-06-14 15:19:27,544 DEBUG  wire <-  "Date: Mon, 14 Jun 2010 14:19:27 GMT[EOL]" 
2010-06-14 15:19:27,544 DEBUG  wire <-  "Content-Type: text/plain;charset=utf-8[EOL]" 
2010-06-14 15:19:27,544 DEBUG  wire <-  "Content-Length: 64[EOL]" 
2010-06-14 15:19:27,545 DEBUG  wire <-  "Cache-Control: must-revalidate[EOL]" 
2010-06-14 15:19:27,545 DEBUG  wire <-  "[EOL]" 
2010-06-14 15:19:27,545 DEBUG  headers <-  HTTP/1.1 401 Unauthorized 
2010-06-14 15:19:27,545 DEBUG  headers <-  Server: CouchDB/0.11.0 (Erlang OTP/R13B) 
2010-06-14 15:19:27,546 DEBUG  headers <-  Date: Mon, 14 Jun 2010 14:19:27 GMT 
2010-06-14 15:19:27,546 DEBUG  headers <-  Content-Type: text/plain;charset=utf-8 
2010-06-14 15:19:27,546 DEBUG  headers <-  Conte开发者_运维问答nt-Length: 64 
2010-06-14 15:19:27,547 DEBUG  headers <-  Cache-Control: must-revalidate 
2010-06-14 15:19:27,548 WARN   DefaultRequestDirector - Authentication error: Unable to respond to any of these challenges: {} 
2010-06-14 15:19:27,548 DEBUG  RESTClient - Response code: 401; found handler: org.codehaus.groovy.runtime.MethodClosure@e2e4d7 
2010-06-14 15:19:27,549 DEBUG  RESTClient - Parsing response as: text/plain 
2010-06-14 15:19:27,549 DEBUG  RESTClient - Parsed data to instance of: class java.io.InputStreamReader 
2010-06-14 15:19:27,550 DEBUG  wire <-  "{"error":"unauthorized","reason":"You are not a server admin."}[\n]" 

Any ideas? doing something stupid? or a bug on someone (who? couchdb or groovy?)

PS No proxies/firewalls/NTLM or anything fancy - all localhost albeit on Windows 7 (development env).

PPS Just quickly tried adding username:password@host to the url - that didn't appear to work either - same error message.

  • Richard


Ok this turns out to be related to a change in CouchDB 0.11 which turns off the basic 401 authentication headers. Now I just need to work out how to turn on pre-authentication for RESTClient/HttpBuilder much like curl does. ref: http://markmail.org/thread/gbky5leiivngglck#query:+page:1+mid:3hraq5ufip2mlpq5+state:results

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号