mirror of
https://github.com/ansible/awx.git
synced 2026-05-22 08:17:39 -02:30
Remove any references to internal licensing utilities
This commit is contained in:
@@ -27,26 +27,6 @@ def mock_no_license_file(mocker):
|
||||
return None
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_license_cannot_be_removed_via_system_settings(mock_no_license_file, get, put, patch, delete, admin, enterprise_license):
|
||||
url = reverse('api:setting_singleton_detail', kwargs={'category_slug': 'system'})
|
||||
response = get(url, user=admin, expect=200)
|
||||
assert not response.data['LICENSE']
|
||||
Setting.objects.create(key='TOWER_URL_BASE', value='https://towerhost')
|
||||
Setting.objects.create(key='LICENSE', value=enterprise_license)
|
||||
response = get(url, user=admin, expect=200)
|
||||
assert response.data['LICENSE']
|
||||
put(url, user=admin, data=response.data, expect=200)
|
||||
response = get(url, user=admin, expect=200)
|
||||
assert response.data['LICENSE']
|
||||
patch(url, user=admin, data={}, expect=200)
|
||||
response = get(url, user=admin, expect=200)
|
||||
assert response.data['LICENSE']
|
||||
delete(url, user=admin, expect=204)
|
||||
response = get(url, user=admin, expect=200)
|
||||
assert response.data['LICENSE']
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_url_base_defaults_to_request(options, admin):
|
||||
# If TOWER_URL_BASE is not set, default to the Tower request hostname
|
||||
@@ -76,10 +56,8 @@ def test_jobs_settings(get, put, patch, delete, admin):
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_ldap_settings(get, put, patch, delete, admin, enterprise_license):
|
||||
def test_ldap_settings(get, put, patch, delete, admin):
|
||||
url = reverse('api:setting_singleton_detail', kwargs={'category_slug': 'ldap'})
|
||||
get(url, user=admin, expect=404)
|
||||
Setting.objects.create(key='LICENSE', value=enterprise_license)
|
||||
get(url, user=admin, expect=200)
|
||||
# The PUT below will fail at the moment because AUTH_LDAP_GROUP_TYPE
|
||||
# defaults to None but cannot be set to None.
|
||||
@@ -102,11 +80,8 @@ def test_ldap_settings(get, put, patch, delete, admin, enterprise_license):
|
||||
'AUTH_LDAP_DENY_GROUP',
|
||||
])
|
||||
@pytest.mark.django_db
|
||||
def test_empty_ldap_dn(get, put, patch, delete, admin, enterprise_license,
|
||||
setting):
|
||||
def test_empty_ldap_dn(get, put, patch, delete, admin, setting):
|
||||
url = reverse('api:setting_singleton_detail', kwargs={'category_slug': 'ldap'})
|
||||
Setting.objects.create(key='LICENSE', value=enterprise_license)
|
||||
|
||||
patch(url, user=admin, data={setting: ''}, expect=200)
|
||||
resp = get(url, user=admin, expect=200)
|
||||
assert resp.data[setting] is None
|
||||
@@ -117,10 +92,8 @@ def test_empty_ldap_dn(get, put, patch, delete, admin, enterprise_license,
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_radius_settings(get, put, patch, delete, admin, enterprise_license, settings):
|
||||
def test_radius_settings(get, put, patch, delete, admin, settings):
|
||||
url = reverse('api:setting_singleton_detail', kwargs={'category_slug': 'radius'})
|
||||
get(url, user=admin, expect=404)
|
||||
Setting.objects.create(key='LICENSE', value=enterprise_license)
|
||||
response = get(url, user=admin, expect=200)
|
||||
put(url, user=admin, data=response.data, expect=200)
|
||||
# Set secret via the API.
|
||||
@@ -151,12 +124,11 @@ def test_radius_settings(get, put, patch, delete, admin, enterprise_license, set
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_ui_settings(get, put, patch, delete, admin, enterprise_license):
|
||||
def test_ui_settings(get, put, patch, delete, admin):
|
||||
url = reverse('api:setting_singleton_detail', kwargs={'category_slug': 'ui'})
|
||||
response = get(url, user=admin, expect=200)
|
||||
assert 'CUSTOM_LOGO' not in response.data
|
||||
assert 'CUSTOM_LOGIN_INFO' not in response.data
|
||||
Setting.objects.create(key='LICENSE', value=enterprise_license)
|
||||
response = get(url, user=admin, expect=200)
|
||||
assert not response.data['CUSTOM_LOGO']
|
||||
assert not response.data['CUSTOM_LOGIN_INFO']
|
||||
|
||||
@@ -1,56 +1,7 @@
|
||||
# Copyright (c) 2015 Ansible, Inc.
|
||||
# All Rights Reserved.
|
||||
|
||||
import time
|
||||
import pytest
|
||||
from datetime import datetime
|
||||
|
||||
from awx.main.models import Host
|
||||
from awx.main.utils import get_licenser, StubLicense
|
||||
from tower_license import TowerLicense
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_license_writer(inventory, admin):
|
||||
license_actual = TowerLicense(
|
||||
company_name='acmecorp',
|
||||
contact_name='Michael DeHaan',
|
||||
contact_email='michael@ansibleworks.com',
|
||||
license_date=25000, # seconds since epoch
|
||||
instance_count=500)
|
||||
|
||||
data = license_actual.generate()
|
||||
|
||||
Host.objects.bulk_create(
|
||||
[
|
||||
Host(
|
||||
name='host.%d' % n,
|
||||
inventory=inventory,
|
||||
created_by=admin,
|
||||
modified=datetime.now(),
|
||||
created=datetime.now())
|
||||
for n in range(12)
|
||||
]
|
||||
)
|
||||
|
||||
assert data['instance_count'] == 500
|
||||
assert data['contact_name'] == 'Michael DeHaan'
|
||||
assert data['contact_email'] == 'michael@ansibleworks.com'
|
||||
assert data['license_date'] == 25000
|
||||
assert data['license_key'] == "11bae31f31c6a6cdcb483a278cdbe98bd8ac5761acd7163a50090b0f098b3a13"
|
||||
|
||||
vdata = license_actual.validate()
|
||||
|
||||
assert vdata['available_instances'] == 500
|
||||
assert vdata['current_instances'] == 12
|
||||
assert vdata['free_instances'] == 488
|
||||
assert vdata['date_warning'] is True
|
||||
assert vdata['date_expired'] is True
|
||||
assert vdata['license_date'] == 25000
|
||||
assert vdata['time_remaining'] < 0
|
||||
assert vdata['valid_key'] is True
|
||||
assert vdata['compliant'] is False
|
||||
assert vdata['subscription_name']
|
||||
from awx.main.utils.common import StubLicense
|
||||
|
||||
|
||||
def test_stub_license():
|
||||
@@ -60,56 +11,3 @@ def test_stub_license():
|
||||
assert license_actual['compliant']
|
||||
assert license_actual['license_type'] == 'open'
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_expired_licenses():
|
||||
license_actual = TowerLicense(
|
||||
company_name='Tower',
|
||||
contact_name='Tower Admin',
|
||||
contact_email='tower@ansible.com',
|
||||
license_date=int(time.time() - 3600),
|
||||
instance_count=100,
|
||||
trial=True)
|
||||
license_actual.generate()
|
||||
vdata = license_actual.validate()
|
||||
|
||||
assert vdata['compliant'] is False
|
||||
assert vdata['grace_period_remaining'] < 0
|
||||
|
||||
license_actual = TowerLicense(
|
||||
company_name='Tower',
|
||||
contact_name='Tower Admin',
|
||||
contact_email='tower@ansible.com',
|
||||
license_date=int(time.time() - 2592001),
|
||||
instance_count=100,
|
||||
trial=False)
|
||||
license_actual.generate()
|
||||
vdata = license_actual.validate()
|
||||
|
||||
assert vdata['compliant'] is False
|
||||
assert vdata['grace_period_remaining'] < 0
|
||||
|
||||
license_actual = TowerLicense(
|
||||
company_name='Tower',
|
||||
contact_name='Tower Admin',
|
||||
contact_email='tower@ansible.com',
|
||||
license_date=int(time.time() - 3600),
|
||||
instance_count=100,
|
||||
trial=False)
|
||||
license_actual.generate()
|
||||
vdata = license_actual.validate()
|
||||
|
||||
assert vdata['compliant'] is False
|
||||
assert vdata['grace_period_remaining'] > 0
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_cloudforms_license(mocker):
|
||||
with mocker.patch('tower_license.TowerLicense._check_cloudforms_subscription', return_value=True):
|
||||
license_actual = TowerLicense()
|
||||
vdata = license_actual.validate()
|
||||
assert vdata['compliant'] is True
|
||||
assert vdata['subscription_name'] == "Red Hat CloudForms License"
|
||||
assert vdata['available_instances'] == 9999999
|
||||
assert vdata['license_type'] == 'enterprise'
|
||||
assert vdata['features']['ha'] is True
|
||||
|
||||
Reference in New Issue
Block a user