2016-10-18 23:44:25 +08:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe FinishInstallationController do
|
|
|
|
|
2018-06-05 13:39:23 +08:00
|
|
|
describe '#index' do
|
2016-10-18 23:44:25 +08:00
|
|
|
context "has_login_hint is false" do
|
|
|
|
before do
|
|
|
|
SiteSetting.has_login_hint = false
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't allow access" do
|
2018-06-05 13:39:23 +08:00
|
|
|
get "/finish-installation"
|
|
|
|
expect(response).to be_forbidden
|
2016-10-18 23:44:25 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "has_login_hint is true" do
|
|
|
|
before do
|
|
|
|
SiteSetting.has_login_hint = true
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
2016-10-18 23:44:25 +08:00
|
|
|
context "has_login_hint is false" do
|
|
|
|
before do
|
|
|
|
SiteSetting.has_login_hint = false
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't allow access" do
|
2018-06-05 13:39:23 +08:00
|
|
|
get "/finish-installation/register"
|
|
|
|
expect(response).to be_forbidden
|
2016-10-18 23:44:25 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "has_login_hint is true" do
|
|
|
|
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
|
|
|
|
|
|
|
|
it "registers the admin when the email is in the list" do
|
2018-06-05 13:39:23 +08:00
|
|
|
expect do
|
|
|
|
post "/finish-installation/register.json", params: {
|
|
|
|
email: 'robin@example.com',
|
|
|
|
username: 'eviltrout',
|
|
|
|
password: 'disismypasswordokay'
|
|
|
|
}
|
|
|
|
end.to change { Jobs::CriticalUserEmail.jobs.size }.by(1)
|
2017-08-31 12:06:56 +08:00
|
|
|
|
2016-10-18 23:44:25 +08:00
|
|
|
expect(response).to be_redirect
|
|
|
|
expect(User.where(username: 'eviltrout').exists?).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-05 13:39:23 +08:00
|
|
|
describe '#confirm_email' do
|
2016-10-18 23:44:25 +08:00
|
|
|
context "has_login_hint is false" do
|
|
|
|
before do
|
|
|
|
SiteSetting.has_login_hint = false
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|