2017-02-15 65 views
0

試圖測試其餘api。在我的項目中沒有用於登錄的API。無論何時你點擊api,它都會被重定向到登錄,接受用戶/密碼並給你結果。如何在Frisby中傳遞基本身份驗證和發佈請求?

我試着GET如下,這對我來說工作得很好。

var frisby = require('frisby') 
    var url = 'https://localhost:8443'; 
    var api= '/api/v2/events/details' 
    var endpoint = '?id=ccce2aef971f' 
    var user= '[email protected]' 
    var pass= 'temp' 

    frisby.create('GET event details based on eventid from an endpoint') 
    .get(url+api+endpoint,{strictSSL: false}) 
    .auth(user,pass,false) 
    .expectStatus(200) 
    .expectHeader('Content-Type', 'application/json;charset=UTF-8') 
    .toss(); 

現在我想用相同的格式但沒有運氣的POST方法作爲迴應。

var frisby = require('frisby') 
var user= '[email protected]' 
var pass= 'temp' 
var jsonbody = {"group": "a10bbd20", 
     "category":"Attack", 
     "notes":"abcdddd", 
     "criteria":[ {"attribute":"PATH" ,"operator": "EQUALS", "value":"/Account/demo.aspx" }] 
     } 

frisby.create('TEST POST') 
.post('https://localhost:8443/api/v2/rule-settings/pointwise',jsonbody,{ json: true },{ headers: { 'Content-Type': 'application/json' }},{strictSSL: false}) 
.auth(user,pass,false) 

.expectStatus(201) 
.toss(); 

======================

我試圖通過存儲從以前的響應Cookie,但仍同樣的錯誤換做POST請求超時

var frisby = require('frisby') 
var url = 'https://localhost:8443'; 
var api= '/api/v2/events/details' 
var endpoint = '?id=ccce2aef971f' 
var user= '[email protected]' 
var pass= 'temp' 


var loginState = { 
}; 


    frisby.create('GET event details based on eventid from an endpoint') 
    .get(url+api+endpoint,{strictSSL: false}) 
    .auth(user,pass,false) 
     .after(function (body,res) { 
      var cookie = res.headers['set-cookie']; 
      console.log(cookie); 
      loginState.user1 = {}; // build an object for user 1 
      loginState.user1.cookie = cookie;     
      var jsonbody = {"group": "a10bbd20", 
          "category":"Attack", 
          "notes":"abcdddd", 
          "criteria":[ {"attribute":"PATH" ,"operator": "EQUALS", "value":"/Account/demo.aspx" }] 
          } 

     frisby.create('TEST POST') 
     .post('https://localhost:8443/api/v2/rule-settings/pointwise',jsonbody,{ json: true },{strictSSL: false}) 
     .addHeader('cookie', loginState.user1.cookie) 
     .addHeader('Content-Type', 'application/json') 
     .inspectRequest() 
     .expectStatus(201) 
     .toss(); 
     }) 

     .toss(); 

輸出我得到的是

Message: 
Expected 500 to equal 200. 
Stacktrace: 
Error: Expected 500 to equal 200. 
at null.<anonymous> (C:\Users\Administrator\Documents\TestSuite\node_modules 
\frisby\lib\frisby.js:493:42) 
at null.<anonymous> (C:\Users\Administrator\Documents\TestSuite\node_modules 
\frisby\lib\frisby.js:1074:43) 
at Timer.listOnTimeout (timers.js:92:15) 

回答

0

我發現夫婦的搜索和弗里斯比發行後的解決方案。

需要添加環境變量來繞過證書。 add process.env.NODE_TLS_REJECT_UNAUTHORIZED =「0」;之前的方法和一切都很好去。

還有一件事情,它也可以和普通的發佈請求一起工作。沒有必要鏈接獲取,張貼在一起的餅乾。

相關問題