Commit 97bfd764 authored by Douwe Maan's avatar Douwe Maan

Add feature specs for license upload.

parent 3a6b9ad8
class License < ActiveRecord::Base
validates :data, presence: true
validate :valid_license
validate :active_user_count, unless: :persisted?
validate :not_expired, unless: :persisted?
......@@ -36,12 +35,6 @@ class License < ActiveRecord::Base
"#{clean_company_name}.gitlab-license"
end
def data_file
return nil unless self.data
Tempfile.new(self.data_filename) { |f| f.write(self.data) }
end
def data_file=(file)
self.data = file.read
end
......
......@@ -18,4 +18,4 @@
= f.file_field :data_file, accept: ".gitlab-license,.gitlab_license,.txt"
.form-actions
= f.submit 'Upload', class: 'btn btn-primary'
= f.submit 'Upload license', class: 'btn btn-primary'
......@@ -89,7 +89,7 @@
- if @previous_licenses.any?
%h4 License History
.panel.panel-default
.panel.panel-default#license_history
%table.table
%thead.panel-heading
%tr
......
@admin
Feature: Admin license
Background:
Given I sign in as an admin
Scenario: Viewing current license
Given there is a license
And I visit admin license page
Then I should see to whom the license is licensed
Scenario: Viewing license when there is none
Given I visit admin license page
Then I should see a warning telling me there is no license
And I should be redirected to the license upload page
Scenario: Viewing expired license
Given there is a license
And the current license is expired
And I visit admin license page
Then I should see a warning telling me the license has expired
Scenario: Viewing license that blocks changes
Given there is a license
And the current license is expired
And the current license blocks changes
And I visit admin license page
Then I should see a warning telling me code pushes have been disabled
Scenario: Viewing license history
Given there is a license
And there are multiple licenses
And I visit admin license page
Then I should see to whom the licenses were licensed
Scenario: Uploading valid license
Given I visit admin upload license page
And I upload a valid license
Then I should see a notice telling me the license was uploaded
And I should see to whom the license is licensed
Scenario: Uploading invalid license
Given I visit admin upload license page
Then I upload an invalid license
Then I should see a warning telling me it's invalid
class Spinach::Features::AdminLicense < Spinach::FeatureSteps
include SharedAuthentication
include SharedPaths
step 'I should see to whom the license is licensed' do
expect(page).to have_content(license.licensee.values.first)
end
step 'there is a license' do
create(:license)
end
step 'I should see a warning telling me there is no license' do
expect(page).to have_content "No GitLab Enterprise Edition license has been provided yet."
end
step 'I should be redirected to the license upload page' do
expect(current_path).to eq(new_admin_license_path)
end
step 'the current license is expired' do
build(:license, data: build(:gitlab_license, expires_at: Date.yesterday).export).save(validate: false)
end
step 'I should see a warning telling me the license has expired' do
expect(page).to have_content "The GitLab Enterprise Edition license expired"
end
step 'the current license blocks changes' do
build(:license, data: build(:gitlab_license, expires_at: Date.yesterday, block_changes_at: Date.today).export).save(validate: false)
end
step 'I should see a warning telling me code pushes have been disabled' do
expect(page).to have_content "Pushing code and creation of issues and merge requests has been disabled."
end
step 'there are multiple licenses' do
create(:license)
create(:license)
end
step 'I should see to whom the licenses were licensed' do
license_history = page.find("#license_history")
License.previous.each do |license|
expect(license_history).to have_content(license.licensee.values.first)
end
end
step 'I visit admin upload license page' do
visit new_admin_license_path
end
step 'I upload a valid license' do
path = Rails.root.join("tmp/valid_license.gitlab-license")
license = build(:gitlab_license)
File.write(path, license.export)
attach_file 'license_data_file', path
click_button "Upload license"
end
step 'I should see a notice telling me the license was uploaded' do
expect(page).to have_content "The license was successfully uploaded and is now active."
end
step 'I upload an invalid license' do
path = Rails.root.join("tmp/invalid_license.gitlab-license")
license = build(:gitlab_license, expires_at: Date.yesterday)
File.write(path, license.export)
attach_file 'license_data_file', path
click_button "Upload license"
end
step "I should see a warning telling me it's invalid" do
expect(page).to have_content "This license has already expired."
end
def license
License.reset_current
License.current
end
end
......@@ -203,6 +203,10 @@ module SharedPaths
visit admin_git_hooks_path
end
step 'I visit admin license page' do
visit admin_license_path
end
# ----------------------------------------
# Generic Project
# ----------------------------------------
......
......@@ -202,4 +202,17 @@ FactoryGirl.define do
provider 'ldapmain'
extern_uid 'my-ldap-id'
end
factory :gitlab_license, class: "Gitlab::License" do
issued_at { Date.today }
licensee do
{ "Name" => Faker::Name.name }
end
notify_users_at { |l| l.expires_at }
notify_admins_at { |l| l.expires_at }
end
factory :license do
data { build(:gitlab_license).export }
end
end
require "spec_helper"
describe License do
let(:gl_license) { Gitlab::License.new(issued_at: Date.today, licensee: { "Name" => "GitLab Test Env" }) }
let(:license) { License.new(data: gl_license.export) }
let(:gl_license) { build(:gitlab_license) }
let(:license) { build(:license, data: gl_license.export) }
describe "Validation" do
describe "Valid license" do
......
......@@ -53,9 +53,7 @@ module TestEnv
def setup_license
Gitlab::License.encryption_key = OpenSSL::PKey::RSA.generate(2048)
gl_license = Gitlab::License.new(issued_at: Date.today, licensee: { "Name" => "GitLab Test Env" })
License.create(data: gl_license.export)
FactoryGirl.create(:license)
end
# Clean /tmp/tests
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment