diff --git a/app/server/tests/test_config.py b/app/server/tests/test_config.py index 2ba3a27d..14a68071 100644 --- a/app/server/tests/test_config.py +++ b/app/server/tests/test_config.py @@ -24,15 +24,23 @@ class TestDatabaseUrl(TestCase): with setenv('DATABASE_URL', 'pgsql://u:p@h/d?sslmode=require'): self._assert_sslmode_is('require') + def test_database_url_with_complex_user(self): + with setenv('DATABASE_URL', 'pgsql://user%40host:p@h/d'): + self._assert_user_is('user@host') + def _assert_sslmode_is(self, expected): - reload(settings) actual = settings.DATABASES['default'].get('OPTIONS', {}).get('sslmode') self.assertEqual(actual, expected) + def _assert_user_is(self, expected): + actual = settings.DATABASES['default'].get('USER', '') + self.assertEqual(actual, expected) + @contextmanager def setenv(key, value): environ[key] = value + reload(settings) yield del environ[key] diff --git a/azuredeploy.json b/azuredeploy.json index e9067d50..1b167d25 100644 --- a/azuredeploy.json +++ b/azuredeploy.json @@ -97,11 +97,15 @@ "databaseSkuTier": "GeneralPurpose", "databaseSkuFamily": "Gen5", "databaseSkuName": "[concat('GP_', variables('databaseSkuFamily'), '_', parameters('databaseCores'))]", - "databaseConnectionString": "[concat('pgsql://', parameters('adminUserName'), '@', variables('databaseServerName'), ':', parameters('adminPassword'), '@', variables('databaseServerName'), '.postgres.database.azure.com:5432/', parameters('databaseName'))]", "databaseVersion": "9.6", + "databaseServerPort": 5432, "databaseServerName": "[concat(parameters('appName'),'-state')]", + "databaseUserCredentials" : "[concat(uriComponent(concat(parameters('adminUserName'), '@', variables('databaseServerName'))), ':', parameters('adminPassword'))]", + "databaseFqdn" : "[concat( variables('databaseServerName'), '.postgres.database.azure.com:', variables('databaseServerPort'))]", + "databaseConnectionString": "[concat('pgsql://', variables('databaseUserCredentials'), '@', variables('databaseFqdn'), '/', parameters('databaseName'))]", "setupScriptName": "[concat(parameters('appName'),'-setup')]", "appServicePlanName": "[concat(parameters('appName'),'-hosting')]", + "appFqdn": "[concat(parameters('appName'),'.azurewebsites.net')]", "analyticsName": "[concat(parameters('appName'),'-analytics')]" }, "resources": [ @@ -269,5 +273,15 @@ "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanName'))]" } } - ] + ], + "outputs": { + "appServer": { + "type": "string", + "value": "[concat(variables('appFqdn'))]" + }, + "databaseServer": { + "type": "string", + "value": "[variables('databaseFqdn')]" + } + } }