drbae3964 2017-04-18 18:03
浏览 50

使用Behat测试登录会话

I am testing an XML and JSON REST API with Behat. For authentication, I use Sentinel. Now, if I log in a user through Behat, and I test the status of the login session, the API returns a negative response (e.g. user not logged in). When I do the exact same thing manually in a browser using AJAX requests, everything works fine. So the end result is fine but the scenario fails. Any suggestions on how to overcome this issue?

UPDATE:

I'll elaborate a bit more on the setup of the app, which is based on Slim, Twig, Eloquent and Sentinel.

The API has some routes to create, show (yes or no) and delete user session. So logging in a user is done by POSTing an email address and password to /session.json or /session.xml. Behind the scenes, the controller will basically call Sentinel::authenticate(...).

This all works fine in the browser. If I perform a GET request to /session.json, I will see the user is logged in correctly. If I follow the same steps with Behat, I will get the right return value on the POST request, so Sentinel says the user is logged in. But the GET request will tell me the user is not logged in.

To give you an idea, the Behat scenario looks something like this:

Scenario Outline: Logging in a user
  Given I have a user with "<email>" and "<password>"
  And I use the "<format>" format
  When I log in the user with "<email>" and "<password>"
  Then the "success" message should be "session.active"

  Examples:
    | email | password | format |
    | a@b.c | 32165487 | xml    |
    | c@b.a | 89056734 | json   |

In the context I use the Requests library to actually perform the requests. So Behat acts as a regular client.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 chaquopy python 安卓
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 有没有帮写代码做实验仿真的
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥30 vmware exsi重置后登不上
    • ¥15 易盾点选的cb参数怎么解啊
    • ¥15 MATLAB运行显示错误,如何解决?
    • ¥15 c++头文件不能识别CDialog
    • ¥15 Excel发现不可读取的内容
    • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题