|
1 | 1 | // Copyright (c) Microsoft Corporation. |
2 | 2 | // Licensed under the MIT License. |
3 | 3 |
|
| 4 | +using System.Text; |
| 5 | + |
4 | 6 | namespace Cli.Tests; |
5 | 7 |
|
6 | 8 | /// <summary> |
@@ -119,6 +121,77 @@ public void TryGenerateConfig_UsingEnvironmentVariable( |
119 | 121 | } |
120 | 122 | } |
121 | 123 |
|
| 124 | + /// <summary> |
| 125 | + /// Test to verify creation of initial config with special characters |
| 126 | + /// such as [!,@,#,$,%,^,&,*, ,(,)] in connection-string or graphql api |
| 127 | + /// </summary> |
| 128 | + [TestMethod] |
| 129 | + public void TestSpecialCharactersInConnectionString() |
| 130 | + { |
| 131 | + HandleConfigFileCreationAndDeletion(TEST_RUNTIME_CONFIG_FILE, configFilePresent: false); |
| 132 | + InitOptions options = new( |
| 133 | + databaseType: DatabaseType.MSSQL, |
| 134 | + connectionString: "A!string@with#some$special%characters^to&check*proper(serialization).'", |
| 135 | + cosmosNoSqlDatabase: null, |
| 136 | + cosmosNoSqlContainer: null, |
| 137 | + graphQLSchemaPath: null, |
| 138 | + graphQLPath: "/An_", |
| 139 | + setSessionContext: false, |
| 140 | + hostMode: HostMode.Production, |
| 141 | + corsOrigin: null, |
| 142 | + authenticationProvider: EasyAuthType.StaticWebApps.ToString(), |
| 143 | + config: TEST_RUNTIME_CONFIG_FILE); |
| 144 | + |
| 145 | + StringBuilder expectedRuntimeConfigJson = new( |
| 146 | + @"{" + |
| 147 | + @"""$schema"": """ + DAB_DRAFT_SCHEMA_TEST_PATH + @"""" + "," + |
| 148 | + @"""data-source"": { |
| 149 | + ""database-type"": ""mssql"", |
| 150 | + ""connection-string"": ""A!string@with#some$special%characters^to&check*proper(serialization).'"", |
| 151 | + ""options"":{ |
| 152 | + ""set-session-context"": false |
| 153 | + } |
| 154 | + }, |
| 155 | + ""runtime"": { |
| 156 | + ""rest"": { |
| 157 | + ""enabled"": true, |
| 158 | + ""path"": ""/api"" |
| 159 | + }, |
| 160 | + ""graphql"": { |
| 161 | + ""enabled"": true, |
| 162 | + ""path"": ""/An_"", |
| 163 | + ""allow-introspection"": true |
| 164 | + }, |
| 165 | + ""host"": { |
| 166 | + ""cors"": { |
| 167 | + ""origins"": [], |
| 168 | + ""allow-credentials"": false |
| 169 | + }, |
| 170 | + ""authentication"": { |
| 171 | + ""provider"": ""StaticWebApps"" |
| 172 | + }, |
| 173 | + ""mode"": ""production"" |
| 174 | + } |
| 175 | + }, |
| 176 | + ""entities"": {} |
| 177 | + }"); |
| 178 | + |
| 179 | + expectedRuntimeConfigJson = expectedRuntimeConfigJson.Replace(" ", string.Empty); |
| 180 | + expectedRuntimeConfigJson = expectedRuntimeConfigJson.Replace("\n", string.Empty); |
| 181 | + expectedRuntimeConfigJson = expectedRuntimeConfigJson.Replace("\r\n", string.Empty); |
| 182 | + |
| 183 | + Assert.IsTrue(TryGenerateConfig(options, _runtimeConfigLoader!, _fileSystem!)); |
| 184 | + |
| 185 | + StringBuilder actualRuntimeConfigJson = new(_fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE, Encoding.Default)); |
| 186 | + actualRuntimeConfigJson = actualRuntimeConfigJson.Replace(" ", string.Empty); |
| 187 | + actualRuntimeConfigJson = actualRuntimeConfigJson.Replace("\r\n", string.Empty); |
| 188 | + actualRuntimeConfigJson = actualRuntimeConfigJson.Replace("\n", string.Empty); |
| 189 | + |
| 190 | + // Comparing explicit strings here since parsing these into JSON would lose |
| 191 | + // the test scenario of verifying escaped chars are not written to the file system. |
| 192 | + Assert.AreEqual(expectedRuntimeConfigJson.ToString(), actualRuntimeConfigJson.ToString()); |
| 193 | + } |
| 194 | + |
122 | 195 | /// <summary> |
123 | 196 | /// This method handles the creation and deletion of a configuration file. |
124 | 197 | /// </summary> |
|
0 commit comments