public static void NegotiateStream_Http_AmbientCredentialsForNet50()
    {
        string testString = "Hello";
        ChannelFactory <IWcfService> factory = null;
        IWcfService serviceProxy             = null;

        try
        {
            // *** SETUP *** \\
            BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
            string host = TestProperties.GetProperty(TestProperties.ServiceUri_PropertyName);

            factory = new ChannelFactory <IWcfService>(
                binding,
                new EndpointAddress(new Uri(Endpoints.Https_WindowsAuth_Address), new SpnEndpointIdentity($"HTTP/{host}")));
            serviceProxy = factory.CreateChannel();

            // *** EXECUTE *** \\
            string result = serviceProxy.Echo(testString);

            // *** VALIDATE *** \\
            Assert.Equal(testString, result);

            // *** CLEANUP *** \\
            ((ICommunicationObject)serviceProxy).Close();
            factory.Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory);
        }
    }
示例#2
0
        /// <summary>
        /// Executes the test script object
        /// </summary>
        /// <param name="testScriptObject"></param>
        /// <param name="testCases"></param>
        private void executeTestScriptObject(ExecutionParameters executionParameters)
        {
            // Structuring this way as eventually the id or build might be a commmand line item for CI/CD
            if (TestProperties.GetProperty("TestRunId") == null)
            {
                // Not previously set, so create test run id and push to test properties.
                TestProperties.SetPropertyValue("TestRunId", DateTime.Now.Ticks.ToString());
            }

            SuppressExecution = executionParameters._suppressExecution;

            _initialTestScriptObject = executionParameters._testScriptObject;

            // Must be a case or step...
            if (executionParameters._testProfile == null)
            {
                executionParameters._testProfile = new TestProfile(1, new TimeSpan(0, 0, 0), "VirtualUser");
            }

            _mainExecutionThread      = new Thread(new ParameterizedThreadStart(executeOnMainThread));
            _mainExecutionThread.Name = "MainExecutionThread";
            _mainExecutionThread.SetApartmentState(ApartmentState.STA);
            _mainExecutionThread.IsBackground = true;
            _mainExecutionThread.Start(executionParameters);
        }
示例#3
0
 public static void OSID_Was_Detected()
 {
     Assert.True(OSHelper.Current != OSID.None,
                 String.Format("OSID was not properly detected from:{0}  TestProperties[TestNugetRuntimeId] = \"{1}\"{0}  RuntimeInformation.OSDescription = \'{2}\"",
                               Environment.NewLine,
                               TestProperties.GetProperty(TestProperties.TestNugetRuntimeId_PropertyName),
                               RuntimeInformation.OSDescription));
 }
 private NegotiateStreamTestConfiguration()
 {
     NegotiateTestRealm    = TestProperties.GetProperty(NegotiateTestRealm_PropertyName);
     NegotiateTestDomain   = TestProperties.GetProperty(NegotiateTestDomain_PropertyName);
     NegotiateTestUserName = TestProperties.GetProperty(NegotiateTestUserName_PropertyName);
     NegotiateTestPassword = TestProperties.GetProperty(NegotiateTestPassword_PropertyName);
     NegotiateTestSpn      = TestProperties.GetProperty(NegotiateTestSpn_PropertyName);
     NegotiateTestUpn      = TestProperties.GetProperty(NegotiateTestUpn_PropertyName);
 }
示例#5
0
    public static bool GetCertificate(out byte[] certificateBytes)
    {
        string endpoint   = Endpoints.Https_DefaultBinding_Address;
        string bridgePort = TestProperties.GetProperty(TestProperties.BridgePort_PropertyName);

        certificateBytes = default(byte[]);

        Uri uri;

        try
        {
            if (Uri.TryCreate(endpoint, UriKind.RelativeOrAbsolute, out uri))
            {
                string certAsPemUri = string.Format(
                    "http://{0}:{1}/resource/WcfService.CertificateResources.CertificateAuthorityResource?exportAsPem=true", uri.Host, bridgePort);

                Console.WriteLine("  Bridge hostname is: '{0}'", uri.Host);
                Console.WriteLine("  Retrieving certificate from:");

                Console.WriteLine(certAsPemUri);
                Console.WriteLine();

                HttpClient client   = new HttpClient();
                var        response = client.GetAsync(certAsPemUri).GetAwaiter().GetResult();

                if (response.IsSuccessStatusCode)
                {
                    certificateBytes = response.Content.ReadAsByteArrayAsync().GetAwaiter().GetResult();
                    Console.WriteLine("    ... read {0} bytes from Bridge", certificateBytes.Length);
                    return(true);
                }
                else
                {
                    Console.WriteLine("  Received an unexpected response from Bridge:{0}  HTTP Status code {1}: '{2}'",
                                      Environment.NewLine,
                                      response.StatusCode,
                                      response.ReasonPhrase);
                    return(false);
                }
            }
            else
            {
                Console.WriteLine("  The Bridge uri specified: '{0}' is an invalid uri", endpoint);
                certificateBytes = null;
                return(false);
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine("  There was an exception thrown while accessing the Bridge at '{0}'", endpoint);
            Console.WriteLine();
            Console.WriteLine(ex);
        }

        return(false);
    }
示例#6
0
    public static void TestProperties_All_Properties_Have_Values()
    {
        IEnumerable <string> propertyNames = TestProperties.PropertyNames;

        foreach (var name in propertyNames)
        {
            string value = TestProperties.GetProperty(name);
            Assert.True(value != null, String.Format("Property '{0}' should not be null.", name));
        }
    }
示例#7
0
    private static Uri BuildBaseUri(string protocol)
    {
        var builder = new UriBuilder();

        builder.Host   = TestProperties.GetProperty(TestProperties.ServiceUri_PropertyName);
        builder.Scheme = protocol;

        if (!IISHosted)
        {
            switch (protocol)
            {
            case "http":
                builder.Port = int.Parse(TestProperties.GetProperty(TestProperties.ServiceHttpPort_PropertyName));
                break;

            case "ws":
                builder.Port   = int.Parse(TestProperties.GetProperty(TestProperties.ServiceWebSocketPort_PropertyName));
                builder.Scheme = "http";
                break;

            case "https":
                builder.Port = int.Parse(TestProperties.GetProperty(TestProperties.ServiceHttpsPort_PropertyName));
                break;

            case "wss":
                builder.Port   = int.Parse(TestProperties.GetProperty(TestProperties.ServiceSecureWebSocketPort_PropertyName));
                builder.Scheme = "https";
                break;

            case "net.tcp":
                builder.Port = int.Parse(TestProperties.GetProperty(TestProperties.ServiceTcpPort_PropertyName));
                break;

            default:
                break;
            }
        }

        return(builder.Uri);
    }
示例#8
0
    private static string GetResourceAddress(string resource, string protocol = "http")
    {
        string host = TestProperties.GetProperty(TestProperties.ServiceUri_PropertyName);

        return(string.Format(@"{0}://{1}/{2}/{3}", protocol, host, TestHostUtilitiesService, resource));
    }
示例#9
0
 static Https_ClientCredentialTypeTests()
 {
     s_username = TestProperties.GetProperty(TestProperties.ExplicitUserName_PropertyName);
     s_password = TestProperties.GetProperty(TestProperties.ExplicitPassword_PropertyName);
 }
示例#10
0
 public static void TestProperties_Throw_KeyNotFoundException()
 {
     Assert.Throws <KeyNotFoundException>(() => TestProperties.GetProperty("NotAProperty"));
 }
示例#11
0
 public static void TestProperties_Throw_ArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>(() => TestProperties.GetProperty(null));
 }
示例#12
0
    public static bool BridgeIsLocalHost()
    {
        string bridgeHost = TestProperties.GetProperty(TestProperties.BridgeHost_PropertyName);

        return(String.Equals("localhost", bridgeHost, StringComparison.OrdinalIgnoreCase));
    }
    // Returns true only if the test services are accessed via "localhost".
    // This test is not intended to be used to determine whether test services
    // are running on the same machine as the tests.
    public static bool IsLocalHost()
    {
        string serviceUri = TestProperties.GetProperty(TestProperties.ServiceUri_PropertyName);

        return(String.Equals("localhost", serviceUri, StringComparison.OrdinalIgnoreCase));
    }
    public static void NegotiateStream_Http_AmbientCredentials()
    {
        string testString = "Hello";
        string result     = "";
        ChannelFactory <IWcfService> factory = null;
        IWcfService serviceProxy             = null;

        try
        {
            // *** SETUP *** \\
            BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;

            factory = new ChannelFactory <IWcfService>(
                binding,
                new EndpointAddress(Endpoints.Https_WindowsAuth_Address));
            serviceProxy = factory.CreateChannel();

            if (Environment.Version.Major == 5 && !OSID.AnyWindows.MatchesCurrent() && !TestProperties.GetProperty(TestProperties.ServiceUri_PropertyName).Contains("/"))
            {
                Assert.Throws <System.ServiceModel.ProtocolException>(() => { result = serviceProxy.Echo(testString); });
            }
            else
            {
                // *** EXECUTE *** \\
                result = serviceProxy.Echo(testString);

                // *** VALIDATE *** \\
                Assert.Equal(testString, result);
            }

            // *** CLEANUP *** \\
            ((ICommunicationObject)serviceProxy).Close();
            factory.Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory);
        }
    }