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

Move token spec to a request spec

Oliver Güntherc75126e05313
diff --git a/spec/features/admin/enterprise/token_domain_spec.rb b/spec/features/admin/enterprise/token_domain_spec.rb
deleted file mode 100644
index adb73e22574..00000000000
--- a/spec/features/admin/enterprise/token_domain_spec.rb
+++ /dev/null
@@ -1,126 +0,0 @@
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2012-2024 the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-# Copyright (C) 2006-2013 Jean-Philippe Lang
-# Copyright (C) 2010-2013 the ChiliProject Team
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# See COPYRIGHT and LICENSE files for more details.
-#++
-
-require "spec_helper"
-
-RSpec.describe "Enterprise Edition token domain", :js, :with_cuprite do
- let(:current_user) { create(:admin) }
- let(:ee_token) { Rails.root.join("spec/fixtures/ee_tokens/v2_1_user_localhost_3001.token").read }
-
- before do
- allow(User).to receive(:current).and_return current_user
- end
-
- shared_context "when uploading a token" do
- before do
- visit "/admin/enterprise"
-
- within "#new_enterprise_token" do
- fill_in "enterprise_token[encoded_token]", with: ee_token
-
- click_on "Save"
- end
- end
- end
-
- describe "initial upload" do
- context "with correct domain", with_settings: { host_name: "localhost:3001" } do
- it_behaves_like "when uploading a token" do
- it "saves the token" do
- expect(body).to have_text "Successful update."
- expect(page).to have_test_selector("ee-active-trial-email", text: "[email protected]")
- end
- end
- end
-
- context "with incorrect domain", with_settings: { host_name: "localhost:3000" } do
- it_behaves_like "when uploading a token" do
- it "shows an invalid domain error" do
- expect(body).to have_text "Domain is invalid."
- end
- end
- end
- end
-
- context "with an active token", with_settings: { host_name: "localhost:3001" } do
- before do
- allow(EnterpriseToken).to receive(:current).and_return(EnterpriseToken.new(encoded_token: ee_token))
-
- visit "/admin/enterprise"
- end
-
- shared_context "when replacing a token" do
- let(:new_token) { raise "define me!" }
-
- before do
- click_on "Replace your current support token"
-
- within "#new_enterprise_token" do
- fill_in "enterprise_token[encoded_token]", with: new_token
- click_on "Save"
- end
- end
- end
-
- it "shows the current token info" do
- expect(page).to have_test_selector("ee-active-trial-email", text: "[email protected]")
- end
-
- describe "replacing the token" do
- context "with correct domain" do
- it_behaves_like "when replacing a token" do
- let(:new_token) { ee_token }
-
- it "updates the token" do
- expect(body).to have_text "Successful update."
- end
- end
- end
-
- context "with incorrect domain" do
- it_behaves_like "when replacing a token" do
- let(:new_token) { Rails.root.join("spec/fixtures/ee_tokens/v2_1_user_localhost_3000.token").read }
-
- it "shows an invalid domain error" do
- expect(body).to have_text "Domain is invalid."
- end
-
- it "shows the new token's info" do
- expect(page).to have_test_selector("ee-active-trial-domain", text: "localhost:3000")
- end
-
- it "but doesn't save the new token" do
- visit "/admin/enterprise"
-
- expect(body).to have_text "localhost:3001"
- end
- end
- end
- end
- end
-end
diff --git a/spec/requests/admin/token_domain_spec.rb b/spec/requests/admin/token_domain_spec.rb
new file mode 100644
index 00000000000..f45533d28e0
--- /dev/null
+++ b/spec/requests/admin/token_domain_spec.rb
@@ -0,0 +1,100 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2024 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+require "spec_helper"
+
+RSpec.describe "Enterprise Edition token domain",
+ :skip_csrf, type: :rails_request, with_settings: { host_name: "localhost:3001" } do
+ let(:current_user) { create(:admin) }
+ let(:valid_token) { Rails.root.join("spec/fixtures/ee_tokens/v2_1_user_localhost_3001.token").read }
+ let(:invalid_token) { Rails.root.join("spec/fixtures/ee_tokens/v2_1_user_localhost_3000.token").read }
+ let(:ee_token) { valid_token }
+
+ before do
+ login_as(current_user)
+ end
+
+ shared_context "when uploading a token" do
+ before do
+ post "/admin/enterprise",
+ params: {
+ "enterprise_token[encoded_token]": ee_token
+ }
+ end
+ end
+
+ describe "initial upload" do
+ context "with correct domain" do
+ it_behaves_like "when uploading a token" do
+ it "saves the token" do
+ expect(response).to be_redirect
+ expect(EnterpriseToken.current).to be_present
+ end
+ end
+ end
+
+ context "with incorrect domain" do
+ let(:ee_token) { invalid_token }
+
+ it_behaves_like "when uploading a token" do
+ it "shows an invalid domain error" do
+ expect(body).to have_text "Domain is invalid."
+ end
+ end
+ end
+ end
+
+ context "with an active token" do
+ let!(:token) do
+ obj = EnterpriseToken.new(encoded_token: invalid_token, created_at: 5.days.ago, updated_at: 5.days.ago)
+ obj.save!(validate: false)
+ obj
+ end
+
+ describe "replacing the token" do
+ context "with correct domain" do
+ it_behaves_like "when uploading a token" do
+ it "updates the token" do
+ expect(response).to be_redirect
+ expect(EnterpriseToken.current.updated_at.to_date).to eq(Time.zone.today)
+ end
+ end
+ end
+
+ context "with incorrect domain" do
+ it_behaves_like "when uploading a token" do
+ let(:ee_token) { invalid_token }
+
+ it "shows an invalid domain error", :aggregate_failures do
+ expect(page).to have_text "Domain is invalid."
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/spec/support/rspec_request_specs.rb b/spec/support/rspec_request_specs.rb
index 2e73d57eb1b..37d38744927 100644
--- a/spec/support/rspec_request_specs.rb
+++ b/spec/support/rspec_request_specs.rb
@@ -6,6 +6,12 @@ module RackTestHelper
end
end
+module CapybaraPage
+ def page
+ Capybara.string(response.body)
+ end
+end
+
RSpec.configure do |config|
# Use Rack::Test for regular request specs (esp. API requests)
config.include RackTestHelper, type: :request
@@ -14,4 +20,5 @@ RSpec.configure do |config|
# (more like a feature spec) with this type.
config.include RSpec::Rails::RequestExampleGroup, type: :rails_request
config.include Capybara::RSpecMatchers, type: :rails_request
+ config.include CapybaraPage, type: :rails_request
end