def post(self): """ Creates the initial super user, updates the underlying configuration and sets the current session to have that super user. """ _reload_config() # Special security check: This method is only accessible when: # - There is a valid config YAML file. # - There are currently no users in the database (clean install) # # We do this special security check because at the point this method is called, the database # is clean but does not (yet) have any super users for our permissions code to check against. if config_provider.config_exists() and not database_has_users(): data = request.get_json() username = data['username'] password = data['password'] email = data['email'] # Create the user in the database. superuser_uuid = model.create_superuser(username, password, email) # Add the user to the config. config_object = config_provider.get_config() config_object['SUPER_USERS'] = [username] config_provider.save_config(config_object) # Update the in-memory config for the new superuser. superusers.register_superuser(username) return {'status': True} abort(403)
def test_registry_status_setup_complete(self): with FreshConfigProvider(): config_provider.save_config({ "key": "value", "SETUP_COMPLETE": True }) json = self.getJsonResponse(SuperUserRegistryStatus) self.assertEqual("config", json["status"])
def put(self): """ Updates the config override file. """ # Note: This method is called to set the database configuration before super users exists, # so we also allow it to be called if there is no valid registry configuration setup. config_object = request.get_json()['config'] # Add any enterprise defaults missing from the config. add_enterprise_config_defaults(config_object, app.config['SECRET_KEY']) # Write the configuration changes to the config override file. config_provider.save_config(config_object) # now try to connect to the db provided in their config to validate it works combined = dict(**app.config) combined.update(config_provider.get_config()) configure(combined, testing=app.config['TESTING']) return {'exists': True, 'config': config_object}
def test_registry_status_db_no_superuser(self): with FreshConfigProvider(): config_provider.save_config({"key": "value"}) json = self.getJsonResponse(SuperUserRegistryStatus) self.assertEqual("create-superuser", json["status"])
def test_registry_status_no_database(self): with FreshConfigProvider(): config_provider.save_config({"key": "value"}) json = self.getJsonResponse(SuperUserRegistryStatus) self.assertEqual("setup-db", json["status"])
def test_registry_status_setup_complete(self): with FreshConfigProvider(): config_provider.save_config({'key': 'value', 'SETUP_COMPLETE': True}) json = self.getJsonResponse(SuperUserRegistryStatus) self.assertEquals('config', json['status'])
def test_registry_status_db_no_superuser(self): with FreshConfigProvider(): config_provider.save_config({'key': 'value'}) json = self.getJsonResponse(SuperUserRegistryStatus) self.assertEquals('create-superuser', json['status'])
def test_registry_status_no_database(self): with FreshConfigProvider(): config_provider.save_config({'key': 'value'}) json = self.getJsonResponse(SuperUserRegistryStatus) self.assertEquals('setup-db', json['status'])