def test_settings_deploy_POST(self): self.client.login(user=factory.make_admin()) osystem = make_usable_osystem(self) osystem_name = osystem["name"] release_name = osystem["default_release"] response = self.client.post( reverse("settings_general"), get_prefixed_form_data( prefix="deploy", data={ "default_osystem": osystem_name, "default_distro_series": "%s/%s" % (osystem_name, release_name), }, ), ) self.assertEqual(http.client.FOUND, response.status_code, response.content) self.assertEqual( (osystem_name, release_name), ( Config.objects.get_config("default_osystem"), Config.objects.get_config("default_distro_series"), ), )
def test_settings_dns_POST(self): # Disable boot source cache signals. self.addCleanup(bootsources.signals.enable) bootsources.signals.disable() self.client.login(user=factory.make_admin()) new_upstream = "8.8.8.8 8.8.4.4" new_ipv4_subnet = factory.make_ipv4_network() new_ipv6_subnet = factory.make_ipv6_network() new_subnets = "%s %s" % (new_ipv4_subnet, new_ipv6_subnet) response = self.client.post( reverse("settings_network"), get_prefixed_form_data( prefix="dns", data={ "upstream_dns": new_upstream, "dnssec_validation": "no", "dns_trusted_acl": new_subnets, }, ), ) self.assertEqual(http.client.FOUND, response.status_code, response.content) self.assertEqual(new_upstream, Config.objects.get_config("upstream_dns")) self.assertEqual("no", Config.objects.get_config("dnssec_validation")) self.assertEqual(new_subnets, Config.objects.get_config("dns_trusted_acl"))
def test_settings_storage_POST(self): self.client.login(user=factory.make_admin()) new_storage_layout = factory.pick_choice(get_storage_layout_choices()) new_enable_disk_erasing_on_release = factory.pick_bool() response = self.client.post( reverse("settings_storage"), get_prefixed_form_data( prefix="storage_settings", data={ "default_storage_layout": new_storage_layout, "enable_disk_erasing_on_release": (new_enable_disk_erasing_on_release), }, ), ) self.assertEqual(http.client.FOUND, response.status_code) self.assertEqual( (new_storage_layout, new_enable_disk_erasing_on_release), ( Config.objects.get_config("default_storage_layout"), Config.objects.get_config("enable_disk_erasing_on_release"), ), )
def test_settings_ubuntu_POST(self): new_main_archive = 'http://test.example.com/archive' new_ports_archive = 'http://test2.example.com/archive' new_cloud_images_archive = 'http://test3.example.com/archive' new_default_distro_series = factory.getRandomEnum(DISTRO_SERIES) response = self.client.post( reverse('settings'), get_prefixed_form_data( prefix='ubuntu', data={ 'main_archive': new_main_archive, 'ports_archive': new_ports_archive, 'cloud_images_archive': new_cloud_images_archive, 'default_distro_series': new_default_distro_series, })) self.assertEqual(httplib.FOUND, response.status_code, response.content) self.assertEqual( ( new_main_archive, new_ports_archive, new_cloud_images_archive, new_default_distro_series, ), ( Config.objects.get_config('main_archive'), Config.objects.get_config('ports_archive'), Config.objects.get_config('cloud_images_archive'), Config.objects.get_config('default_distro_series'), ))
def test_settings_commissioning_POST(self): new_after_commissioning = factory.getRandomEnum( NODE_AFTER_COMMISSIONING_ACTION) new_check_compatibility = factory.getRandomBoolean() new_commissioning_distro_series = factory.getRandomEnum(DISTRO_SERIES) response = self.client.post( reverse('settings'), get_prefixed_form_data( prefix='commissioning', data={ 'after_commissioning': new_after_commissioning, 'check_compatibility': new_check_compatibility, 'commissioning_distro_series': new_commissioning_distro_series, })) self.assertEqual(httplib.FOUND, response.status_code) self.assertEqual( ( new_after_commissioning, new_check_compatibility, new_commissioning_distro_series, ), ( Config.objects.get_config('after_commissioning'), Config.objects.get_config('check_compatibility'), Config.objects.get_config('commissioning_distro_series'), ))
def test_edit_user_POST_profile_update_creates_audit_event(self): self.client_log_in(as_admin=True) user = factory.make_User() new_username = factory.make_name('newname') params = make_user_attribute_params(user) last_name = factory.make_name('Newname') email = '*****@*****.**' % factory.make_string() is_superuser = True params.update({ 'last_name': last_name, 'email': email, 'is_superuser': is_superuser, 'username': new_username, }) self.client.post( reverse('accounts-edit', args=[user.username]), get_prefixed_form_data('profile', params)) event = Event.objects.get(type__level=AUDIT) self.assertIsNotNone(event) self.assertEquals( event.description, ( "User profile (username: %s, full name: %s, email: %s, " "administrator: %s)" ) % (new_username, last_name, email, is_superuser) + " updated by '%(username)s'.")
def test_settings_deploy_POST(self): self.client.login(user=factory.make_admin()) osystem = make_usable_osystem(self) osystem_name = osystem['name'] release_name = osystem['default_release'] response = self.client.post( reverse('settings_general'), get_prefixed_form_data(prefix='deploy', data={ 'default_osystem': osystem_name, 'default_distro_series': '%s/%s' % ( osystem_name, release_name, ), })) self.assertEqual(http.client.FOUND, response.status_code, response.content) self.assertEqual(( osystem_name, release_name, ), ( Config.objects.get_config('default_osystem'), Config.objects.get_config('default_distro_series'), ))
def test_prefs_POST_password(self): # The preferences page allows the user to change their password. user = factory.make_User() self.client.login(username=user.username, password="******") user.set_password("password") old_pw = user.password response = self.client.post( "/account/prefs/", get_prefixed_form_data( "password", { "old_password": "******", "new_password1": "new", "new_password2": "new", }, ), ) self.assertEqual(http.client.FOUND, response.status_code) user = reload_object(user) # The password is SHA1ized, we just make sure that it has changed. self.assertNotEqual(old_pw, user.password) event = Event.objects.get(type__level=AUDIT) self.assertIsNotNone(event) self.assertEqual(event.description, "Updated password.")
def test_edit_user_POST_profile_update_creates_audit_event(self): self.client.login(user=factory.make_admin()) user = factory.make_User() new_username = factory.make_name("newname") params = make_user_attribute_params(user) last_name = factory.make_name("Newname") email = "*****@*****.**" % factory.make_string() is_superuser = True params.update({ "last_name": last_name, "email": email, "is_superuser": is_superuser, "username": new_username, }) self.client.post( reverse("accounts-edit", args=[user.username]), get_prefixed_form_data("profile", params), ) event = Event.objects.get(type__level=AUDIT) self.assertIsNotNone(event) self.assertEquals( event.description, ("Updated user profile (username: %s, full name: %s, " + "email: %s, administrator: %s)") % (new_username, last_name, email, is_superuser), )
def test_settings_commissioning_POST(self): new_after_commissioning = factory.getRandomEnum( NODE_AFTER_COMMISSIONING_ACTION) new_check_compatibility = factory.getRandomBoolean() new_commissioning_distro_series = factory.getRandomEnum(DISTRO_SERIES) response = self.client.post( reverse('settings'), get_prefixed_form_data( prefix='commissioning', data={ 'after_commissioning': new_after_commissioning, 'check_compatibility': new_check_compatibility, 'commissioning_distro_series': ( new_commissioning_distro_series), })) self.assertEqual(httplib.FOUND, response.status_code) self.assertEqual( ( new_after_commissioning, new_check_compatibility, new_commissioning_distro_series, ), ( Config.objects.get_config('after_commissioning'), Config.objects.get_config('check_compatibility'), Config.objects.get_config('commissioning_distro_series'), ))
def test_edit_user_POST_updates_password(self): user = factory.make_user() new_password = factory.getRandomString() params = make_password_params(new_password) response = self.client.post( reverse('accounts-edit', args=[user.username]), get_prefixed_form_data('password', params)) self.assertEqual(httplib.FOUND, response.status_code) self.assertTrue(reload_object(user).check_password(new_password))
def test_edit_user_POST_password_update_creates_audit_event(self): self.client.login(user=factory.make_admin()) user = factory.make_User() new_password = factory.make_string() params = make_password_params(new_password) self.client.post(reverse('accounts-edit', args=[user.username]), get_prefixed_form_data('password', params)) event = Event.objects.get(type__level=AUDIT) self.assertIsNotNone(event) self.assertEquals(event.description, "Updated password.")
def test_prefs_post_profile_external_auth(self): user = factory.make_User() self.client.login(user=user) # log in the user locally so it doesn't need macaroons Config.objects.set_config("external_auth_url", "http://example.com") params = {"last_name": "John Doe", "email": "*****@*****.**"} response = self.client.post( "/account/prefs/", get_prefixed_form_data("profile", params) ) self.assertEqual(http.client.METHOD_NOT_ALLOWED, response.status_code)
def test_edit_user_POST_updates_password(self): self.client.login(user=factory.make_admin()) user = factory.make_User() new_password = factory.make_string() params = make_password_params(new_password) response = self.client.post( reverse("accounts-edit", args=[user.username]), get_prefixed_form_data("password", params), ) self.assertEqual(http.client.FOUND, response.status_code) self.assertTrue(reload_object(user).check_password(new_password))
def test_prefs_post_profile_external_auth(self): user = factory.make_User() self.client.login(user=user) # log in the user locally so it doesn't need macaroons Config.objects.set_config('external_auth_url', 'http://example.com') params = { 'last_name': 'John Doe', 'email': '*****@*****.**', } response = self.client.post('/account/prefs/', get_prefixed_form_data('profile', params)) self.assertEqual(http.client.METHOD_NOT_ALLOWED, response.status_code)
def test_settings_kernelopts_POST(self): self.client.login(user=factory.make_admin()) new_kernel_opts = "--new='arg' --flag=1 other" response = self.client.post( reverse("settings_general"), get_prefixed_form_data(prefix="kernelopts", data={"kernel_opts": new_kernel_opts}), ) self.assertEqual(http.client.FOUND, response.status_code) self.assertEqual(new_kernel_opts, Config.objects.get_config("kernel_opts"))
def test_settings_kernelopts_POST(self): self.client_log_in(as_admin=True) new_kernel_opts = "--new='arg' --flag=1 other" response = self.client.post( reverse('settings'), get_prefixed_form_data(prefix='kernelopts', data={ 'kernel_opts': new_kernel_opts, })) self.assertEqual(http.client.FOUND, response.status_code) self.assertEqual(new_kernel_opts, Config.objects.get_config('kernel_opts'))
def test_prefs_POST_profile(self): # The preferences page allows the user the update its profile # information. params = { 'last_name': 'John Doe', 'email': '*****@*****.**', } response = self.client.post('/account/prefs/', get_prefixed_form_data('profile', params)) self.assertEqual(httplib.FOUND, response.status_code) user = User.objects.get(id=self.logged_in_user.id) self.assertAttributes(user, params)
def test_prefs_POST_profile(self): # The preferences page allows the user the update its profile # information. user = factory.make_User() self.client.login(user=user) params = {"last_name": "John Doe", "email": "*****@*****.**"} response = self.client.post( "/account/prefs/", get_prefixed_form_data("profile", params) ) self.assertEqual(http.client.FOUND, response.status_code) user = reload_object(user) self.assertAttributes(user, params)
def test_prefs_POST_profile(self): # The preferences page allows the user the update its profile # information. params = { 'last_name': 'John Doe', 'email': '*****@*****.**', } response = self.client.post( '/account/prefs/', get_prefixed_form_data('profile', params)) self.assertEqual(httplib.FOUND, response.status_code) user = User.objects.get(id=self.logged_in_user.id) self.assertAttributes(user, params)
def test_settings_kernelopts_POST(self): new_kernel_opts = "--new='arg' --flag=1 other" response = self.client.post( reverse('settings'), get_prefixed_form_data( prefix='kernelopts', data={ 'kernel_opts': new_kernel_opts, })) self.assertEqual(httplib.FOUND, response.status_code) self.assertEqual( new_kernel_opts, Config.objects.get_config('kernel_opts'))
def test_settings_maas_POST(self): # Disable boot source cache signals. self.addCleanup(bootsources.signals.enable) bootsources.signals.disable() self.client.login(user=factory.make_admin()) new_name = factory.make_string() response = self.client.post( reverse("settings_general"), get_prefixed_form_data(prefix="maas", data={"maas_name": new_name}), ) self.assertEqual(http.client.FOUND, response.status_code, response.content) self.assertEqual(new_name, Config.objects.get_config("maas_name"))
def test_settings_third_party_drivers_POST(self): self.client.login(user=factory.make_admin()) new_enable_third_party_drivers = factory.pick_bool() response = self.client.post( reverse('settings_general'), get_prefixed_form_data(prefix='third_party_drivers', data={ 'enable_third_party_drivers': (new_enable_third_party_drivers), })) self.assertEqual(http.client.FOUND, response.status_code) self.assertEqual( (new_enable_third_party_drivers, ), (Config.objects.get_config('enable_third_party_drivers'), ))
def test_settings_vcenter_POST(self): self.client.login(user=factory.make_admin()) vcenter = { 'vcenter_server': factory.make_name('vcenter_server'), 'vcenter_username': factory.make_name('vcenter_username'), 'vcenter_password': factory.make_name('vcenter_password'), 'vcenter_datacenter': factory.make_name('vcenter_datacenter'), } response = self.client.post( reverse('settings_general'), get_prefixed_form_data(prefix='vcenter', data=vcenter), ) self.assertEqual(http.client.FOUND, response.status_code) self.assertDictEqual(vcenter, Config.objects.get_configs(vcenter.keys()))
def test_prefs_POST_password_external_auth(self): user = factory.make_User() self.client.login(username=user.username, password='******') user.set_password('password') # log in the user locally so it doesn't need macaroons Config.objects.set_config('external_auth_url', 'http://example.com') response = self.client.post( '/account/prefs/', get_prefixed_form_data( 'password', { 'old_password': '******', 'new_password1': 'new', 'new_password2': 'new', })) self.assertEqual(http.client.METHOD_NOT_ALLOWED, response.status_code)
def test_settings_maas_POST(self): # Disable boot source cache signals. self.addCleanup(bootsources.signals.enable) bootsources.signals.disable() self.client_log_in(as_admin=True) new_name = factory.make_string() response = self.client.post( reverse('settings'), get_prefixed_form_data(prefix='maas', data={ 'maas_name': new_name, })) self.assertEqual(http.client.FOUND, response.status_code, response.content) self.assertEqual(new_name, Config.objects.get_config('maas_name'))
def test_settings_commissioning_POST(self): self.client.login(user=factory.make_admin()) ubuntu = factory.make_default_ubuntu_release_bootable() new_commissioning = ubuntu.name.split('/')[1] response = self.client.post( reverse('settings_general'), get_prefixed_form_data(prefix='commissioning', data={ 'commissioning_distro_series': (new_commissioning), })) self.assertEqual(http.client.FOUND, response.status_code) self.assertEqual( (new_commissioning, ), (Config.objects.get_config('commissioning_distro_series'), ))
def test_edit_user_POST_profile_updates_attributes(self): user = factory.make_user() params = make_user_attribute_params(user) params.update({ 'last_name': factory.make_name('Newname'), 'email': '*****@*****.**' % factory.getRandomString(), 'is_superuser': True, 'username': factory.make_name('newname'), }) response = self.client.post( reverse('accounts-edit', args=[user.username]), get_prefixed_form_data('profile', params)) self.assertEqual(httplib.FOUND, response.status_code) self.assertAttributes( reload_object(user), subset_dict(params, user_attributes))
def test_prefs_POST_password(self): # The preferences page allows the user to change his password. self.logged_in_user.set_password('password') old_pw = self.logged_in_user.password response = self.client.post( '/account/prefs/', get_prefixed_form_data( 'password', { 'old_password': '******', 'new_password1': 'new', 'new_password2': 'new', })) self.assertEqual(httplib.FOUND, response.status_code) user = User.objects.get(id=self.logged_in_user.id) # The password is SHA1ized, we just make sure that it has changed. self.assertNotEqual(old_pw, user.password)
def test_settings_ntp_POST(self): # Disable boot source cache signals. self.addCleanup(bootsources.signals.enable) bootsources.signals.disable() self.client.login(user=factory.make_admin()) new_servers = "ntp.example.com" response = self.client.post( reverse('settings_network'), get_prefixed_form_data(prefix='ntp', data={ 'ntp_servers': new_servers, 'ntp_external_only': True, })) self.assertEqual(http.client.FOUND, response.status_code, response.content) self.assertEqual(new_servers, Config.objects.get_config('ntp_servers')) self.assertTrue(Config.objects.get_config('ntp_external_only'))
def test_settings_dns_POST(self): # Disable boot source cache signals. self.addCleanup(bootsources.signals.enable) bootsources.signals.disable() self.client_log_in(as_admin=True) new_upstream = "8.8.8.8" response = self.client.post( reverse('settings'), get_prefixed_form_data(prefix='dns', data={ 'upstream_dns': new_upstream, 'dnssec_validation': 'no', })) self.assertEqual(http.client.FOUND, response.status_code, response.content) self.assertEqual(new_upstream, Config.objects.get_config('upstream_dns')) self.assertEqual('no', Config.objects.get_config('dnssec_validation'))
def test_prefs_POST_password_external_auth(self): user = factory.make_User() self.client.login(username=user.username, password="******") user.set_password("password") # log in the user locally so it doesn't need macaroons Config.objects.set_config("external_auth_url", "http://example.com") response = self.client.post( "/account/prefs/", get_prefixed_form_data( "password", { "old_password": "******", "new_password1": "new", "new_password2": "new", }, ), ) self.assertEqual(http.client.METHOD_NOT_ALLOWED, response.status_code)
def test_proxy_proxy_POST(self): # Disable boot source cache signals. self.addCleanup(bootsources.signals.enable) bootsources.signals.disable() self.client.login(user=factory.make_admin()) new_proxy = "http://%s.example.com:1234/" % factory.make_string() response = self.client.post( reverse('settings_network'), get_prefixed_form_data(prefix='proxy', data={ 'http_proxy': new_proxy, 'enable_http_proxy': True, 'use_peer_proxy': True, })) self.assertEqual(http.client.FOUND, response.status_code, response.content) self.assertEqual(new_proxy, Config.objects.get_config('http_proxy')) self.assertTrue(Config.objects.get_config('enable_http_proxy')) self.assertTrue(Config.objects.get_config('use_peer_proxy'))
def test_settings_maas_and_network_POST(self): # Disable the DNS machinery so that we can skip the required # setup. self.patch(settings, "DNS_CONNECT", False) new_name = factory.getRandomString() new_domain = factory.getRandomString() new_proxy = "http://%s.example.com:1234/" % factory.getRandomString() response = self.client.post( reverse('settings'), get_prefixed_form_data( prefix='maas_and_network', data={ 'maas_name': new_name, 'enlistment_domain': new_domain, 'http_proxy': new_proxy, })) self.assertEqual(httplib.FOUND, response.status_code, response.content) self.assertEqual( (new_name, new_domain, new_proxy), (Config.objects.get_config('maas_name'), Config.objects.get_config('enlistment_domain'), Config.objects.get_config('http_proxy')))