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

Fixes #38108 - As a user I want to invalidate tokens for self(UI) #10405

Merged
merged 1 commit into from
Jan 8, 2025

Conversation

girijaasoni
Copy link
Contributor

No description provided.

@github-actions github-actions bot added the UI label Dec 17, 2024
@girijaasoni girijaasoni force-pushed the 38108 branch 2 times, most recently from f3234ce to 95f093f Compare December 17, 2024 13:05
Copy link

@Lennonka Lennonka left a comment

Choose a reason for hiding this comment

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

Microcopy review

<h1>{__('JWT Tokens')}</h1>
<p>
{__(
'By invalidating tokens,you will no longer be able to register hosts by using their JWTs.'

Choose a reason for hiding this comment

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

Suggested change
'By invalidating tokens,you will no longer be able to register hosts by using their JWTs.'
'By invalidating your JSON Web Tokens (JWTs), you will no longer be able to register hosts by using your existing JWTs.'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks!

process_success(
:success_msg => _('Successfully invalidated JWTs for %s.') % @user.login
)
unless editing_self?
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this change? Why not to have same response as before?

Copy link
Member

Choose a reason for hiding this comment

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

@girijaasoni I think we should use respond_to here. It would be more consistent.

test "User should be able to invalidate jwt for self" do
User.current = users(:one)
user = User.current
FactoryBot.build(:jwt_secret, token: 'test_jwt_secret', user: user)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
FactoryBot.build(:jwt_secret, token: 'test_jwt_secret', user: user)
FactoryBot.create(:jwt_secret, token: 'test_jwt_secret', user: user)

With build the object is not saved in the database, making the assertion pass even if the action was not performing correctly

@girijaasoni girijaasoni force-pushed the 38108 branch 3 times, most recently from d19a69c to c0c8fdb Compare December 24, 2024 14:08
process_success(
:success_msg => _('Successfully invalidated JWTs for %s.') % @user.login
)
unless editing_self?
Copy link
Member

Choose a reason for hiding this comment

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

@girijaasoni I think we should use respond_to here. It would be more consistent.

)
unless editing_self?
process_success(
:success_msg => _('Successfully invalidated JWTs for %s.') % @user.login
Copy link
Member

@ShimShtein ShimShtein Dec 25, 2024

Choose a reason for hiding this comment

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

Suggested change
:success_msg => _('Successfully invalidated JWTs for %s.') % @user.login
:success_msg => _('Successfully invalidated registration tokens for %s.') % @user.login

@@ -18,6 +18,9 @@
<% if @editing_self || (@user.persisted? && authorized_for(hash_for_api_user_personal_access_tokens_path(user_id: @user))) %>
<li><a href='#personal_access_tokens' data-toggle='tab'><%= _('Personal Access Tokens') %></a></li>
<% end %>
<% if @editing_self %>
<li><a href='#jwt_tokens' data-toggle='tab'><%= _('JWT Tokens') %></a></li>
Copy link
Member

@ShimShtein ShimShtein Dec 25, 2024

Choose a reason for hiding this comment

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

Suggested change
<li><a href='#jwt_tokens' data-toggle='tab'><%= _('JWT Tokens') %></a></li>
<li><a href='#jwt_tokens' data-toggle='tab'><%= _('Registration Tokens') %></a></li>

FactoryBot.create(:jwt_secret, token: 'test_jwt_secret', user: user)
patch :invalidate_jwt, params: { :id => user.id }, session: set_session_user(User.current)
user.reload
assert_response :success
Copy link
Member

Choose a reason for hiding this comment

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

Please add assertion for the user object:

assert_nil user.jwt_token

test/controllers/users_controller_test.rb Show resolved Hide resolved
test/controllers/users_controller_test.rb Show resolved Hide resolved
@nofaralfasi
Copy link
Contributor

@stejskalleos Could you please approve this PR so that I can merge it?

@nofaralfasi nofaralfasi merged commit 68c95ba into theforeman:develop Jan 8, 2025
60 of 65 checks passed
@nofaralfasi
Copy link
Contributor

Thanks everyone!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants