public void FriendlyFeedsInMediumTrust() { string savedPath = LocalWebServerHelper.FileTargetPath; LocalWebServerHelper.Cleanup(); try { string[] trustLevels = new string[] { null, "High", "Medium" }; LocalWebServerHelper.FileTargetPath = Path.Combine(Path.GetTempPath(), "SecurityPartialTrustTest"); IOUtil.EnsureEmptyDirectoryExists(LocalWebServerHelper.FileTargetPath); LocalWebServerHelper.StartWebServer(); TestUtil.RunCombinations(trustLevels, (trustLevel) => { // Setup partial trust service. SetupPartialTrustService(trustLevel); string address, text = null; Exception exception; address = "http://localhost:" + LocalWebServerHelper.LocalPortNumber + "/service.svc/$metadata"; Trace.WriteLine("Requesting " + address); exception = TestUtil.RunCatching(delegate() { text = new WebClient().DownloadString(address); }); WriteExceptionOrText(exception, text); TestUtil.AssertExceptionExpected(exception, false); }); } finally { LocalWebServerHelper.DisposeProcess(); LocalWebServerHelper.Cleanup(); LocalWebServerHelper.FileTargetPath = savedPath; } }
public void SecurityPartialTrustTest() { // Repro: Astoria not working in partial trust with the EF string savedPath = LocalWebServerHelper.FileTargetPath; LocalWebServerHelper.Cleanup(); try { string[] trustLevels = new string[] { null, "High", "Medium" }; CombinatorialEngine engine = CombinatorialEngine.FromDimensions( new Dimension("trustLevel", trustLevels)); LocalWebServerHelper.FileTargetPath = Path.Combine(Path.GetTempPath(), "SecurityPartialTrustTest"); IOUtil.EnsureEmptyDirectoryExists(LocalWebServerHelper.FileTargetPath); LocalWebServerHelper.StartWebServer(); TestUtil.RunCombinatorialEngineFail(engine, delegate(Hashtable values) { string trustLevel = (string)values["trustLevel"]; if (trustLevel == "Medium") { Trace.WriteLine( "'Medium' trust level cannot be tested reliably in unit tests, " + "because it may run into problems depending on the local file system " + "permissions and/or the local web server (as far as can be told). " + "You can still use the generated files to prop them to IIS, set up an application " + "and test there."); return; } // Setup partial trust service. SetupPartialTrustService(trustLevel); string address, text = null; Exception exception; address = "http://localhost:" + LocalWebServerHelper.LocalPortNumber + "/service.svc/ASet?$expand=NavB"; Trace.WriteLine("Requesting " + address); exception = TestUtil.RunCatching(delegate() { text = new WebClient().DownloadString(address); }); WriteExceptionOrText(exception, text); // Note: the second argument should be 'false' even for medium trust. TestUtil.AssertExceptionExpected(exception, false); // Invoke something that would normally fail. address = "http://localhost:" + LocalWebServerHelper.LocalPortNumber + "/service.svc/Q"; text = null; Trace.WriteLine("Requesting " + address); exception = TestUtil.RunCatching(delegate() { text = new WebClient().DownloadString(address); }); WriteExceptionOrText(exception, text); TestUtil.AssertExceptionExpected(exception, trustLevel == "Medium" && !text.Contains("error") // The error may come in the body ); }); } finally { LocalWebServerHelper.DisposeProcess(); LocalWebServerHelper.Cleanup(); LocalWebServerHelper.FileTargetPath = savedPath; } }