Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for passwords#edit when redirect_whitelist is set #1247

Merged

Conversation

MaicolBen
Copy link
Collaborator

Missing tests from #1228

put :edit,
params: { email: '[email protected]' }
get_reset_token
get :edit, params: { reset_password_token: @mail_reset_token}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was wrong lol, I am glad that I did this

Copy link
Contributor

@dks17 dks17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could replace these parts by get_reset_token, they look the same:

        describe 'case-sensitive email' do
          before do
            post :create,
                 params: { email: @resource.email,
                           redirect_url: @redirect_url }

            @mail = ActionMailer::Base.deliveries.last
            @resource.reload
            @data = JSON.parse(response.body)

            @mail_config_name  = CGI.unescape(@mail.body.match(/config=([^&]*)&/)[1])
            @mail_redirect_url = CGI.unescape(@mail.body.match(/redirect_url=([^&]*)&/)[1])
            @mail_reset_token  = @mail.body.match(/reset_password_token=(.*)\"/)[1]
          end
    describe 'Alternate user class' do
      before do
        @resource = create(:mang_user, :confirmed)
        @redirect_url = 'http://ng-token-auth.dev'

        post :create, params: { email: @resource.email,
                                redirect_url: @redirect_url }

        @mail = ActionMailer::Base.deliveries.last
        @resource.reload

        @mail_config_name  = CGI.unescape(@mail.body.match(/config=([^&]*)&/)[1])
        @mail_redirect_url = CGI.unescape(@mail.body.match(/redirect_url=([^&]*)&/)[1])
        @mail_reset_token  = @mail.body.match(/reset_password_token=(.*)\"/)[1]
      end
    describe 'alternate user type' do
      before do
        @resource = create(:user, :confirmed)
        @config_name  = 'altUser'

        post :create, params: { email: @resource.email,
                                redirect_url: @redirect_url,
                                config_name: @config_name }

        @mail = ActionMailer::Base.deliveries.last
        @resource.reload

        @mail_config_name  = CGI.unescape(@mail.body.match(/config=([^&]*)&/)[1])
        @mail_redirect_url = CGI.unescape(@mail.body.match(/redirect_url=([^&]*)&/)[1])
        @mail_reset_token  = @mail.body.match(/reset_password_token=(.*)\"/)[1]
      end

@@ -66,10 +66,9 @@ class DeviseTokenAuth::PasswordsControllerTest < ActionController::TestCase
describe 'for edit' do
before do
@auth_headers = @resource.create_new_auth_token
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also delete this:

Suggested change
@auth_headers = @resource.create_new_auth_token

because it appears in another before block which is above:

describe 'not redirect_url should return 401' do
  before do
    @auth_headers = @resource.create_new_auth_token
    @new_password = Faker::Internet.password
  end

Copy link
Contributor

@dks17 dks17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, everything looks good.

@dks17
Copy link
Contributor

dks17 commented Jan 9, 2019

Some tests failed. I have released PR #1249 to fix it.

@MaicolBen MaicolBen force-pushed the chore/add-blacklist-edit-tests branch 9 times, most recently from 867ddea to 4f6d9c5 Compare January 14, 2019 02:01
@MaicolBen MaicolBen force-pushed the chore/add-blacklist-edit-tests branch from 4f6d9c5 to 9ba635c Compare January 14, 2019 02:13
@MaicolBen MaicolBen merged commit fb7a24a into lynndylanhurley:master Jan 14, 2019
@MaicolBen MaicolBen deleted the chore/add-blacklist-edit-tests branch January 14, 2019 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants