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