0

我有一个使用 ember-simple-auth 设计的 rails 后端和 ember cli 项目,我正在尝试进行 Qunit 测试以涵盖经过身份验证post的 Rails。我不是在嘲笑任何后端调用。

我的测试是这样设置的:

test('successfully POSTing', function(){
  // helper to signin through ember
  signIn();

  andThen(function(){
    // fill out a form and submit it  
    equal(find('li').text(), 'aodsfiu');

  })
});

simple-auth-session-store:ephemeral在我的测试环境中使用。

助手工作正常:我可以从signIn()ember 和 rails 日志中看到它提交表单并返回 status 201,但是以下请求返回状态,401如身份验证信息从未保存/未在以下请求中使用。

如果我手动测试它,一切都很好,这让我认为这是测试环境的问题,但是当我删除它时,store:ephemeral我仍然401从我的服务器中恢复状态。

如何在测试环境中使用 ember-simple-auth 向我的服务器发出经过身份验证的请求?有没有办法直接访问测试会话数据并设置user-tokenandemail以便 Rails 认为我已通过身份验证?

环境:

if (environment === 'test') {
    // simple auth local storage stuff
    ENV['simple-auth'] = {
      authorizer: 'simple-auth-authorizer:devise',
      crossOriginWhitelist: ['*'],
      store: 'simple-auth-session-store:ephemeral',

    }
    // Testem prefers this...
    ENV.baseURL = '/';
    ENV.locationType = 'auto';

    // keep test console output quieter
    ENV.APP.LOG_ACTIVE_GENERATION = false;
    ENV.APP.LOG_VIEW_LOOKUPS = false;

    ENV.APP.rootElement = '#ember-testing';
  }
4

1 回答 1

1

The ephemeral store only makes sure that the session isn't actually persisted so that tests don't influence each other. What you see might be caused by Ember Simple Auth's cross origin authorization policy - as long as you don't whitelist an origin requests going to it will not be authorized so that your token doesn't get exposed to arbitrary sites. See the API docs.

于 2014-12-01T08:10:19.520 回答