2011-10-27 101 views
2

我正在進行需要身份驗證的集成測試。 會話狀態(即Cookie)似乎不會被請求保持。 有沒有CookieManager或類似的東西?如何使用Groovy HttpBuilder在兩個請求之間保持會話狀態

@Test 
public void whenAuthenticatedUserRequestAForbiddenUrlShouldObtain403() { 
    def client = new RESTClient('http://127.0.0.1:8080/app/') 

    def login = client .post(
      path: 'api/login.json', 
      body: [j_username: 'user', j_password: 'test'], 
      requestContentType: ContentType.URLENC) 



    def resp = client .get(path: 'forbidden-url') 
    assert (resp.status == 403) 
    ==> FAILS status = 200 
} 

回答

0

它看起來對我來說,問題不丟失會話狀態,而是「禁止-URL」可能不被指定爲在第一時間安全。如果是這樣,即使您登錄,似乎客戶端請求請求也不會成功。嘗試刪除頂部的登錄名,如果您仍然擁有200個,那麼您可能無法保證網址安全。

相關問題