Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

added specs for new token screen

Jonas Jabari379dd1fcc330
diff --git a/app/views/my/access_token_partials/_api_tokens_section.html.erb b/app/views/my/access_token_partials/_api_tokens_section.html.erb
index 6a879d7c3b0..9175fc794fe 100644
--- a/app/views/my/access_token_partials/_api_tokens_section.html.erb
+++ b/app/views/my/access_token_partials/_api_tokens_section.html.erb
@@ -26,7 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
See COPYRIGHT and LICENSE files for more details.
++#%>
-<div class="attributes-group">
+<div class="attributes-group" id="api-token-section">
<div class="attributes-group--header">
<div class="attributes-group--header-container">
<h3 class="attributes-group--header-text"><%= t("my_account.access_tokens.api.title") %></h3>
@@ -63,6 +63,7 @@ See COPYRIGHT and LICENSE files for more details.
<%= link_to "",
{ action: 'revoke_api_key' },
method: :delete,
+ data: { confirm: t('my_account.access_tokens.simple_revoke_confirmation') },
class: 'icon icon-delete' %>
</td>
</tr>
diff --git a/app/views/my/access_token_partials/_icalendar_tokens_section.html.erb b/app/views/my/access_token_partials/_icalendar_tokens_section.html.erb
index 696dceed91d..6cf9c3ad6c6 100644
--- a/app/views/my/access_token_partials/_icalendar_tokens_section.html.erb
+++ b/app/views/my/access_token_partials/_icalendar_tokens_section.html.erb
@@ -26,7 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
See COPYRIGHT and LICENSE files for more details.
++#%>
-<div class="attributes-group">
+<div class="attributes-group" id="icalendar-token-section">
<div class="attributes-group--header">
<div class="attributes-group--header-container">
<h3 class="attributes-group--header-text"><%= t("my_account.access_tokens.ical.title") %></h3>
@@ -77,6 +77,7 @@ See COPYRIGHT and LICENSE files for more details.
<td style="text-align: right;">
<%= link_to "",
{ action: 'revoke_ical_token', id: token.id },
+ data: { confirm: t('my_account.access_tokens.simple_revoke_confirmation') },
method: :delete,
class: 'icon icon-delete' %>
</td>
diff --git a/app/views/my/access_token_partials/_oauth_tokens_section.html.erb b/app/views/my/access_token_partials/_oauth_tokens_section.html.erb
index e0ed43b483e..50eca4d2f6b 100644
--- a/app/views/my/access_token_partials/_oauth_tokens_section.html.erb
+++ b/app/views/my/access_token_partials/_oauth_tokens_section.html.erb
@@ -26,7 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
See COPYRIGHT and LICENSE files for more details.
++#%>
-<div class="attributes-group">
+<div class="attributes-group" id="oauth-token-section">
<div class="attributes-group--header">
<div class="attributes-group--header-container">
<h3 class="attributes-group--header-text"><%= t("my_account.access_tokens.oauth.title") %></h3>
diff --git a/app/views/my/access_token_partials/_rss_tokens_section.html.erb b/app/views/my/access_token_partials/_rss_tokens_section.html.erb
index 4db42a807ec..ca9b61d927e 100644
--- a/app/views/my/access_token_partials/_rss_tokens_section.html.erb
+++ b/app/views/my/access_token_partials/_rss_tokens_section.html.erb
@@ -26,7 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
See COPYRIGHT and LICENSE files for more details.
++#%>
-<div class="attributes-group">
+<div class="attributes-group" id="rss-token-section">
<div class="attributes-group--header">
<div class="attributes-group--header-container">
<h3 class="attributes-group--header-text"><%= t("my_account.access_tokens.rss.title") %></h3>
@@ -63,6 +63,7 @@ See COPYRIGHT and LICENSE files for more details.
<%= link_to "",
{ action: 'revoke_rss_key' },
method: :delete,
+ data: { confirm: t('my_account.access_tokens.simple_revoke_confirmation') },
class: 'icon icon-delete' %>
</td>
</tr>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 571dd63fc11..69fc4dc7fb3 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -1522,6 +1522,7 @@ en:
action: "Action"
expiration: "Expires"
indefinite_expiration: "Never"
+ simple_revoke_confirmation: "Are you sure you want to revoke this token?"
api:
title: "API"
text_hint: "API tokens allow third-party applications to communicate with this OpenProject instance via REST APIs."
diff --git a/spec/features/users/my_spec.rb b/spec/features/users/my_spec.rb
index 52922c92a53..702e424a16b 100644
--- a/spec/features/users/my_spec.rb
+++ b/spec/features/users/my_spec.rb
@@ -124,115 +124,303 @@ RSpec.describe 'my', js: true, with_cuprite: true do
end
end
- it 'in Access Tokens they can generate their API key' do
- visit my_access_token_path
- expect(page).to have_content 'Missing API access key'
- find(:xpath, "//tr[contains(.,'API')]/td/a", text: 'Generate').click
+ describe "API tokens" do
+ context 'when API access is disabled via global settings', with_settings: { rest_api_enabled: false } do
+ it 'shows notice about disabled token' do
+ visit my_access_token_path
- expect(page).to have_content 'A new API token has been generated. Your access token is'
+ within '#api-token-section' do
+ expect(page).to have_content('API tokens are not enabled by the administrator.')
+ expect(page).not_to have_xpath("//a//span[text()='API token']")
+ end
+ end
+ end
- User.current.reload
- visit my_access_token_path
+ context 'when API access is enabled via global settings', with_settings: { rest_api_enabled: true } do
+ it 'API tokens can generated and revoked' do
+ visit my_access_token_path
- expect(page).not_to have_content 'Missing API access key'
- end
+ expect(page).not_to have_content('API tokens are not enabled by the administrator.')
- it 'in Access Tokens they can generate their RSS key' do
- visit my_access_token_path
- expect(page).to have_content 'Missing RSS access key'
- find(:xpath, "//tr[contains(.,'RSS')]/td/a", text: 'Generate').click
+ within '#api-token-section' do
+ expect(page).to have_xpath("//a//span[text()='API token']")
+ find(:xpath, "//a//span[text()='API token']").click
+ end
- expect(page).to have_content 'A new RSS token has been generated. Your access token is'
+ expect(page).to have_content 'A new API token has been generated. Your access token is'
- User.current.reload
- visit my_access_token_path
+ User.current.reload
+ visit my_access_token_path
- expect(page).not_to have_content 'Missing RSS access key'
- end
+ # only one API token can be created
+ within '#api-token-section' do
+ expect(page).not_to have_xpath("//a//span[text()='API token']")
+ end
- describe "iCalendar tokens" do
- let!(:project) { create(:project) }
- let!(:query) { create(:query, project:) }
- let!(:another_query) { create(:query, project:) }
+ # revoke API token
+ within '#api-token-section' do
+ expect(page).to have_css("a.icon-delete")
+ accept_confirm do
+ find("a.icon-delete").click
+ end
+ end
- it 'in Access Tokens they can see if iCalendar tokens exists grouped by query and project' do
- visit my_access_token_path
+ expect(page).to have_content 'The API token has been deleted.'
+
+ User.current.reload
+ visit my_access_token_path
- within(:xpath, "//tr[contains(.,'iCalendar')]") do
- expect(page).to have_content 'iCalendar token(s) not present'
+ # API token can be created again
+ within '#api-token-section' do
+ expect(page).to have_xpath("//a//span[text()='API token']")
+ end
end
+ end
+ end
- ical_token_for_query = create(:ical_token, user:, query:, name: "Some Token Name")
+ describe "RSS tokens" do
+ context 'when RSS access is disabled via global settings', with_settings: { feeds_enabled: false } do
+ it 'shows notice about disabled token' do
+ visit my_access_token_path
- visit my_access_token_path
+ within '#rss-token-section' do
+ expect(page).to have_content('RSS tokens are not enabled by the administrator.')
+ expect(page).not_to have_xpath("//a//span[text()='RSS token']")
+ end
+ end
+ end
- expect(page).not_to have_content 'iCalendar token(s) not present'
+ context 'when RSS access is enabled via global settings', with_settings: { feeds_enabled: true } do
+ it 'in Access Tokens they can generate and revoke their RSS key' do
+ visit my_access_token_path
- token_name = ical_token_for_query.ical_token_query_assignment.name
+ expect(page).not_to have_content('RSS tokens are not enabled by the administrator.')
- expected_content = "iCalendar token \"#{token_name}\" for \"#{query.name}\" in \"#{project.name}\""
+ within '#rss-token-section' do
+ expect(page).to have_xpath("//a//span[text()='RSS token']")
+ find(:xpath, "//a//span[text()='RSS token']").click
+ end
- within(:xpath, "//tr[contains(.,'#{expected_content}')]") do
- expect(page).to have_content expected_content
- expect(page).to have_content I18n.l(ical_token_for_query.created_at, format: :time).to_s
- end
+ expect(page).to have_content 'A new RSS token has been generated. Your access token is'
+
+ User.current.reload
+ visit my_access_token_path
- Timecop.travel(1.minute.from_now) do
- another_ical_token_for_query = create(:ical_token, user:, query:, name: "Some Other Token Name")
+ # only one RSS token can be created
+ within '#rss-token-section' do
+ expect(page).not_to have_xpath("//a//span[text()='RSS token']")
+ end
+ # revoke RSS token
+ within '#rss-token-section' do
+ expect(page).to have_css("a.icon-delete")
+ accept_confirm do
+ find("a.icon-delete").click
+ end
+ end
+
+ expect(page).to have_content 'The RSS token has been deleted.'
+
+ User.current.reload
visit my_access_token_path
- token_name = another_ical_token_for_query.ical_token_query_assignment.name
+ # RSS token can be created again
+ within '#rss-token-section' do
+ expect(page).to have_xpath("//a//span[text()='RSS token']")
+ end
+ end
+ end
+ end
- expected_content = "iCalendar token \"#{token_name}\" for \"#{query.name}\" in \"#{project.name}\""
+ describe "iCalendar tokens" do
+ context 'when iCalendar access is disabled via global settings', with_settings: { ical_enabled: false } do
+ it 'shows notice about disabled token' do
+ visit my_access_token_path
- within(:xpath, "//tr[contains(.,'#{expected_content}')]") do
- expect(page).to have_content expected_content
- expect(page).to have_content I18n.l(another_ical_token_for_query.created_at, format: :time).to_s
+ within '#icalendar-token-section' do
+ expect(page).to have_content('iCalendar subscriptions are not enabled by the administrator.')
end
end
+ end
- Timecop.travel(2.minutes.from_now) do
- ical_token_for_another_query = create(:ical_token, user:, query: another_query, name: "Some Token Name")
+ context 'when iCalendar access is enable via global settings', with_settings: { ical_enabled: true } do
+ context 'when no iCalendar token exists' do
+ it 'shows notice about how to use iCalendar tokens' do
+ visit my_access_token_path
- visit my_access_token_path
+ within '#icalendar-token-section' do
+ expect(page).to have_content('To add an iCalendar token') # ...
+ end
+ end
+ end
+
+ context 'when multiple iCalendar tokens exist' do
+ let!(:project) { create(:project) }
+ let!(:query) { create(:query, project:) }
+ let!(:another_query) { create(:query, project:) }
+ let!(:ical_token_for_query) { create(:ical_token, user:, query:, name: "First Token Name") }
+ let!(:ical_token_for_another_query) { create(:ical_token, user:, query: another_query, name: "Second Token Name") }
+ let!(:second_ical_token_for_query) { create(:ical_token, user:, query:, name: "Third Token Name") }
+
+ it 'shows iCalendar tokens with their calender and project info' do
+ visit my_access_token_path
+
+ expect(page).not_to have_content('To add an iCalendar token') # ...
+
+ within '#icalendar-token-section' do
+ [
+ ical_token_for_query,
+ ical_token_for_another_query,
+ second_ical_token_for_query
+ ].each do |ical_token|
+ token_name = ical_token.ical_token_query_assignment.name
+ query = ical_token.ical_token_query_assignment.query
+ row_xpath = "//tr[td[1][contains(text(), '#{token_name}')]]"
+
+ expect(page).to have_xpath("#{row_xpath}/td[1]", text: token_name)
+ expect(page).to have_xpath("#{row_xpath}/td[2]/a", text: query.name)
+ expect(page).to have_xpath("#{row_xpath}/td[3]", text: query.project.name)
+ end
+ end
+ end
+
+ it 'single iCalendar tokens can be deleted' do
+ visit my_access_token_path
+ token_name = ical_token_for_query.ical_token_query_assignment.name
+ row_xpath = "//tr[td[1][contains(text(), '#{token_name}')]]"
+
+ within '#icalendar-token-section' do
+ accept_confirm do
+ find(:xpath, "#{row_xpath}/td//a[@class='icon icon-delete']").click
+ end
+ end
- token_name = ical_token_for_another_query.ical_token_query_assignment.name
+ expect(page).to have_content 'The iCalendar URL with this token is now invalid.'
- expected_content = "iCalendar token \"#{token_name}\" for \"#{another_query.name}\" in \"#{project.name}\""
+ User.current.reload
+ visit my_access_token_path
- within(:xpath, "//tr[contains(.,'#{expected_content}')]") do
- expect(page).to have_content expected_content
- expect(page).to have_content I18n.l(ical_token_for_another_query.created_at, format: :time).to_s
+ within '#icalendar-token-section' do
+ expect(page).not_to have_xpath("#{row_xpath}/td//a[@class='icon icon-delete']")
+ end
end
end
end
+ end
+
+ describe "OAuth tokens" do
+ context 'when no OAuth access is configured' do
+ it 'shows notice about no existing tokens' do
+ visit my_access_token_path
+
+ within '#oauth-token-section' do
+ expect(page).to have_content('There is no third-party application access configured and active for you')
+ end
+ end
+ end
+
+ context 'when OAuth access is configured' do
+ let!(:app) do
+ create(:oauth_application,
+ name: 'Some App',
+ confidential: false)
+ end
+ let!(:token_for_app) do
+ create(:oauth_access_token,
+ application: app,
+ resource_owner: user)
+ end
+ let!(:second_app) do
+ create(:oauth_application,
+ name: 'Some Second App',
+ uid: '56789',
+ confidential: false)
+ end
+ let!(:token_for_second_app) do
+ create(:oauth_access_token,
+ application: second_app,
+ resource_owner: user)
+ end
- it 'in Access Tokens they can revoke all existing Ical tokens' do
- ical_token_for_query = create(:ical_token, user:, query:, name: "Some Token Name")
- create(:ical_token, user:, query:, name: "Some Other Token Name")
- create(:ical_token, user:, query: another_query, name: "Some Token Name")
+ context 'when single OAuth token per app is configured' do
+ it 'shows token for granted applications' do
+ visit my_access_token_path
- expect(user.ical_tokens.count).to eq 3
+ [app, second_app].each do |app|
+ within '#oauth-token-section' do
+ expect(page).to have_xpath("//tr[td[1][contains(text(), '#{app.name}')]]")
+ expect(page).to have_xpath("//tr[td[1][contains(text(), '(one active token)')]]")
+ end
+ end
+ end
- visit my_access_token_path
+ it 'can revoke tokens' do
+ visit my_access_token_path
- token_name = ical_token_for_query.ical_token_query_assignment.name
+ [app, second_app].each do |app|
+ row_xpath = "//tr[td[1][contains(text(), '#{app.name}')]]"
- expected_content = "iCalendar token \"#{token_name}\" for \"#{query.name}\" in \"#{project.name}\""
+ within '#oauth-token-section' do
+ accept_confirm do
+ find(:xpath, "#{row_xpath}/td//a[@class='icon icon-delete']").click
+ end
+ end
+ end
- within(:xpath, "//tr[contains(.,'#{expected_content}')]") do
- expect(page).to have_content "Revoke"
- click_link "Revoke"
+ User.current.reload
+ visit my_access_token_path
+
+ [app, second_app].each do |app|
+ row_xpath = "//tr[td[1][contains(text(), '#{app.name}')]]"
+ within '#oauth-token-section' do
+ expect(page).not_to have_xpath("#{row_xpath}/td//a[@class='icon icon-delete']")
+ end
+ end
+ end
end
- expect(page).to have_content(
- "\"#{token_name}\" for calendar \"#{query.name}\" of project \"#{project.name}\" has been revoked."
- )
+ context 'when multiple OAuth tokens per app are configured' do
+ let!(:second_token_for_app) do
+ create(:oauth_access_token,
+ application: app,
+ resource_owner: user)
+ end
+ let!(:second_token_for_second_app) do
+ create(:oauth_access_token,
+ application: second_app,
+ resource_owner: user)
+ end
- expect(page).not_to have_content expected_content
+ it 'shows token for granted applications' do
+ visit my_access_token_path
- expect(user.ical_tokens.count).to eq 2
+ [app, second_app].each do |app|
+ within '#oauth-token-section' do
+ expect(page).to have_xpath("//tr[td[1][contains(text(), '#{app.name}')]]")
+ expect(page).to have_xpath("//tr[td[1][contains(text(), '(2 active token)')]]")
+ end
+ end
+ end
+
+ it 'can revoke mutliple tokens per app' do
+ visit my_access_token_path
+
+ row_xpath = "//tr[td[1][contains(text(), '#{app.name}')]]"
+
+ within '#oauth-token-section' do
+ accept_confirm do
+ find(:xpath, "#{row_xpath}/td//a[@class='icon icon-delete']").click
+ end
+ end
+
+ User.current.reload
+ visit my_access_token_path
+
+ within '#oauth-token-section' do
+ expect(page).not_to have_xpath("#{row_xpath}/td//a[@class='icon icon-delete']")
+ end
+ end
+ end
end
end
end