2019-10-22 03:06:00 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-06-06 19:14:09 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
require Rails.root.join('db', 'post_migrate', '20190524073827_schedule_fill_valid_time_for_pages_domain_certificates.rb')
|
|
|
|
|
2020-06-24 18:09:03 +00:00
|
|
|
RSpec.describe ScheduleFillValidTimeForPagesDomainCertificates do
|
2019-06-06 19:14:09 +00:00
|
|
|
let(:migration_class) { described_class::MIGRATION }
|
|
|
|
let(:migration_name) { migration_class.to_s.demodulize }
|
|
|
|
|
|
|
|
let(:domains_table) { table(:pages_domains) }
|
|
|
|
|
|
|
|
let(:certificate) do
|
|
|
|
File.read('spec/fixtures/passphrase_x509_certificate.crt')
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
domains_table.create!(domain: "domain1.example.com", verification_code: "123")
|
|
|
|
domains_table.create!(domain: "domain2.example.com", verification_code: "123", certificate: '')
|
|
|
|
domains_table.create!(domain: "domain3.example.com", verification_code: "123", certificate: certificate)
|
|
|
|
domains_table.create!(domain: "domain4.example.com", verification_code: "123", certificate: certificate)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'correctly schedules background migrations' do
|
|
|
|
Sidekiq::Testing.fake! do
|
2020-08-31 15:10:41 +00:00
|
|
|
freeze_time do
|
2019-06-06 19:14:09 +00:00
|
|
|
migrate!
|
|
|
|
|
|
|
|
first_id = domains_table.find_by_domain("domain3.example.com").id
|
|
|
|
last_id = domains_table.find_by_domain("domain4.example.com").id
|
|
|
|
|
|
|
|
expect(migration_name).to be_scheduled_delayed_migration(5.minutes, first_id, last_id)
|
|
|
|
expect(BackgroundMigrationWorker.jobs.size).to eq(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-23 09:06:03 +00:00
|
|
|
it 'sets certificate valid_not_before/not_after', :sidekiq_might_not_need_inline do
|
2019-06-06 19:14:09 +00:00
|
|
|
perform_enqueued_jobs do
|
|
|
|
migrate!
|
|
|
|
|
|
|
|
domain = domains_table.find_by_domain("domain3.example.com")
|
|
|
|
expect(domain.certificate_valid_not_before)
|
|
|
|
.to eq(Time.parse("2018-03-23 14:02:08 UTC"))
|
|
|
|
expect(domain.certificate_valid_not_after)
|
|
|
|
.to eq(Time.parse("2019-03-23 14:02:08 UTC"))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|