2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe FinishInstallationController do
|
2018-06-05 01:39:23 -04:00
|
|
|
describe "#index" do
|
2022-07-27 12:14:14 -04:00
|
|
|
context "when has_login_hint is false" do
|
2016-10-18 11:44:25 -04:00
|
|
|
before { SiteSetting.has_login_hint = false }
|
|
|
|
|
|
|
|
it "doesn't allow access" do
|
2018-06-05 01:39:23 -04:00
|
|
|
get "/finish-installation"
|
2023-12-28 23:44:41 -05:00
|
|
|
expect(response.status).to eq(403)
|
2016-10-18 11:44:25 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
context "when has_login_hint is true" do
|
2016-10-18 11:44:25 -04:00
|
|
|
before { SiteSetting.has_login_hint = true }
|
|
|
|
|
|
|
|
it "allows access" do
|
2018-06-05 01:39:23 -04:00
|
|
|
get "/finish-installation"
|
|
|
|
expect(response.status).to eq(200)
|
2016-10-18 11:44:25 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-05 01:39:23 -04:00
|
|
|
describe "#register" do
|
2022-07-27 12:14:14 -04:00
|
|
|
context "when has_login_hint is false" do
|
2016-10-18 11:44:25 -04:00
|
|
|
before { SiteSetting.has_login_hint = false }
|
|
|
|
|
|
|
|
it "doesn't allow access" do
|
2018-06-05 01:39:23 -04:00
|
|
|
get "/finish-installation/register"
|
2023-12-28 23:44:41 -05:00
|
|
|
expect(response.status).to eq(403)
|
2016-10-18 11:44:25 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
context "when has_login_hint is true" do
|
2016-10-18 11:44:25 -04:00
|
|
|
before do
|
|
|
|
SiteSetting.has_login_hint = true
|
|
|
|
GlobalSetting.stubs(:developer_emails).returns("robin@example.com")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "allows access" do
|
2018-06-05 01:39:23 -04:00
|
|
|
get "/finish-installation/register"
|
|
|
|
expect(response.status).to eq(200)
|
2016-10-18 11:44:25 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "raises an error when the email is not in the allowed list" do
|
2018-06-05 01:39:23 -04:00
|
|
|
post "/finish-installation/register.json",
|
|
|
|
params: {
|
2018-01-11 22:15:10 -05:00
|
|
|
email: "notrobin@example.com",
|
|
|
|
username: "eviltrout",
|
|
|
|
password: "disismypasswordokay",
|
2018-06-05 01:39:23 -04:00
|
|
|
}
|
2018-01-11 22:15:10 -05:00
|
|
|
expect(response.status).to eq(400)
|
2016-10-18 11:44:25 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't redirect when fields are wrong" do
|
2018-06-05 01:39:23 -04:00
|
|
|
post "/finish-installation/register",
|
|
|
|
params: {
|
2017-08-31 00:06:56 -04:00
|
|
|
email: "robin@example.com",
|
|
|
|
username: "",
|
|
|
|
password: "disismypasswordokay",
|
|
|
|
}
|
|
|
|
|
2016-10-18 11:44:25 -04:00
|
|
|
expect(response).not_to be_redirect
|
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
context "with working params" do
|
2018-08-21 13:11:18 -04:00
|
|
|
let(:params) do
|
2018-06-05 01:39:23 -04:00
|
|
|
{ email: "robin@example.com", username: "eviltrout", password: "disismypasswordokay" }
|
2018-08-21 13:11:18 -04:00
|
|
|
end
|
2017-08-31 00:06:56 -04:00
|
|
|
|
2018-08-21 13:11:18 -04:00
|
|
|
it "registers the admin when the email is in the list" do
|
|
|
|
expect do post "/finish-installation/register.json", params: params end.to change {
|
|
|
|
Jobs::CriticalUserEmail.jobs.size
|
|
|
|
}.by(1)
|
|
|
|
|
|
|
|
expect(response).to be_redirect
|
|
|
|
expect(User.where(username: "eviltrout").exists?).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "automatically resends the signup email when the user already exists" do
|
|
|
|
expect do post "/finish-installation/register.json", params: params end.to change {
|
|
|
|
Jobs::CriticalUserEmail.jobs.size
|
|
|
|
}.by(1)
|
|
|
|
|
|
|
|
expect(User.where(username: "eviltrout").exists?).to eq(true)
|
|
|
|
|
|
|
|
expect do post "/finish-installation/register.json", params: params end.to change {
|
|
|
|
Jobs::CriticalUserEmail.jobs.size
|
|
|
|
}.by(1)
|
|
|
|
|
|
|
|
expect(response).to be_redirect
|
|
|
|
expect(User.where(username: "eviltrout").exists?).to eq(true)
|
|
|
|
end
|
2016-10-18 11:44:25 -04:00
|
|
|
end
|
2018-08-21 13:11:18 -04:00
|
|
|
|
2018-08-22 01:45:24 -04:00
|
|
|
it "sets the admins trust level" do
|
|
|
|
post "/finish-installation/register.json",
|
|
|
|
params: {
|
|
|
|
email: "robin@example.com",
|
|
|
|
username: "eviltrout",
|
|
|
|
password: "disismypasswordokay",
|
|
|
|
}
|
2023-01-09 06:18:21 -05:00
|
|
|
|
2018-08-22 01:45:24 -04:00
|
|
|
expect(User.find_by(username: "eviltrout").trust_level).to eq 1
|
|
|
|
end
|
2016-10-18 11:44:25 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-05 01:39:23 -04:00
|
|
|
describe "#confirm_email" do
|
2022-07-27 12:14:14 -04:00
|
|
|
context "when has_login_hint is false" do
|
2016-10-18 11:44:25 -04:00
|
|
|
before { SiteSetting.has_login_hint = false }
|
|
|
|
|
|
|
|
it "shows the page" do
|
2018-06-05 01:39:23 -04:00
|
|
|
get "/finish-installation/confirm-email"
|
|
|
|
expect(response.status).to eq(200)
|
2016-10-18 11:44:25 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-10-21 11:34:19 -04:00
|
|
|
|
2018-06-05 01:39:23 -04:00
|
|
|
describe "#resend_email" do
|
2016-10-21 11:34:19 -04:00
|
|
|
before do
|
|
|
|
SiteSetting.has_login_hint = true
|
|
|
|
GlobalSetting.stubs(:developer_emails).returns("robin@example.com")
|
2017-08-31 00:06:56 -04:00
|
|
|
|
2018-06-05 01:39:23 -04:00
|
|
|
post "/finish-installation/register",
|
|
|
|
params: {
|
2017-08-31 00:06:56 -04:00
|
|
|
email: "robin@example.com",
|
|
|
|
username: "eviltrout",
|
|
|
|
password: "disismypasswordokay",
|
|
|
|
}
|
2016-10-21 11:34:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "resends the email" do
|
2018-06-05 01:39:23 -04:00
|
|
|
expect do put "/finish-installation/resend-email" end.to change {
|
|
|
|
Jobs::CriticalUserEmail.jobs.size
|
|
|
|
}.by(1)
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
2016-10-21 11:34:19 -04:00
|
|
|
end
|
|
|
|
end
|
2016-10-18 11:44:25 -04:00
|
|
|
end
|