示例#1
0
        public async Task OneTimeSetUpAsync()
        {
            // this test fails on macOS, ignore (TODO)
            if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                Assert.Ignore("Reverse connect fails on mac OS.");
            }

            // pki directory root for test runs.
            PkiRoot = Path.GetTempPath() + Path.GetRandomFileName();

            // start ref server with reverse connect
            ServerFixture = new ServerFixture <ReferenceServer> {
                AutoAccept            = true,
                SecurityNone          = true,
                ReverseConnectTimeout = MaxTimeout,
                TraceMasks            = Utils.TraceMasks.Error | Utils.TraceMasks.Security
            };
            ReferenceServer = await ServerFixture.StartAsync(TestContext.Out, PkiRoot).ConfigureAwait(false);

            // create client
            ClientFixture = new ClientFixture();
            await ClientFixture.LoadClientConfiguration(PkiRoot).ConfigureAwait(false);

            await ClientFixture.StartReverseConnectHost().ConfigureAwait(false);

            m_endpointUrl = new Uri(Utils.ReplaceLocalhost("opc.tcp://localhost:" + ServerFixture.Port.ToString()));
            // start reverse connection
            ReferenceServer.AddReverseConnection(new Uri(ClientFixture.ReverseConnectUri), MaxTimeout);
        }
        public async Task OneTimeSetUpAsync()
        {
            // this test fails on macOS, ignore
            if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                Assert.Ignore("Reverse connect fails on mac OS.");
            }

            // start ref server
            m_serverFixture = new ServerFixture <ReferenceServer> {
                AutoAccept            = true,
                SecurityNone          = true,
                ReverseConnectTimeout = MaxTimeout,
                TraceMasks            = Utils.TraceMasks.Error | Utils.TraceMasks.Security
            };
            m_server = await m_serverFixture.StartAsync(TestContext.Out).ConfigureAwait(false);

            // create client
            m_clientFixture = new ClientFixture();
            await m_clientFixture.LoadClientConfiguration().ConfigureAwait(false);

            await m_clientFixture.StartReverseConnectHost().ConfigureAwait(false);

            m_endpointUrl = new Uri(Utils.ReplaceLocalhost("opc.tcp://localhost:" + m_serverFixture.Port.ToString()));
            // start reverse connection
            m_server.AddReverseConnection(new Uri(m_clientFixture.ReverseConnectUri), MaxTimeout);
        }
示例#3
0
        /// <summary>
        /// Setup a server and client fixture.
        /// </summary>
        /// <param name="writer">The test output writer.</param>
        public async Task OneTimeSetUpAsync(TextWriter writer = null)
        {
            // start Ref server
            m_serverFixture = new ServerFixture <ReferenceServer> {
                UriScheme       = m_uriScheme,
                SecurityNone    = true,
                AutoAccept      = true,
                OperationLimits = true
            };
            if (writer != null)
            {
                m_serverFixture.TraceMasks = Utils.TraceMasks.Error;
            }
            m_server = await m_serverFixture.StartAsync(writer ?? TestContext.Out).ConfigureAwait(false);

            m_clientFixture = new ClientFixture();
            await m_clientFixture.LoadClientConfiguration().ConfigureAwait(false);

            m_clientFixture.Config.TransportQuotas.MaxMessageSize    =
                m_clientFixture.Config.TransportQuotas.MaxBufferSize = 4 * 1024 * 1024;
            m_url = new Uri(m_uriScheme + "://localhost:" + m_serverFixture.Port.ToString());
            try
            {
                m_session = await m_clientFixture.ConnectAsync(m_url, SecurityPolicies.Basic256Sha256).ConfigureAwait(false);
            }
            catch (Exception e)
            {
                Assert.Ignore("OneTimeSetup failed to create session, tests skipped. Error: {0}", e.Message);
            }
        }
        /// <summary>
        /// Setup a server and client fixture.
        /// </summary>
        /// <param name="writer">The test output writer.</param>
        public async Task OneTimeSetUpAsync(TextWriter writer = null)
        {
            // start Ref server
            m_serverFixture                 = new ServerFixture <ReferenceServer>();
            m_clientFixture                 = new ClientFixture();
            m_serverFixture.AutoAccept      = true;
            m_serverFixture.OperationLimits = true;
            if (writer != null)
            {
                m_serverFixture.TraceMasks = Utils.TraceMasks.Error | Utils.TraceMasks.Security;
            }
            m_server = await m_serverFixture.StartAsync(writer ?? TestContext.Out).ConfigureAwait(false);

            await m_clientFixture.LoadClientConfiguration().ConfigureAwait(false);

            m_url     = new Uri("opc.tcp://localhost:" + m_serverFixture.Port.ToString());
            m_session = await m_clientFixture.ConnectAsync(m_url, SecurityPolicies.Basic256Sha256).ConfigureAwait(false);
        }
        /// <summary>
        /// Setup a server and client fixture.
        /// </summary>
        /// <param name="writer">The test output writer.</param>
        public async Task OneTimeSetUpAsync(TextWriter writer = null)
        {
            // pki directory root for test runs.
            PkiRoot = Path.GetTempPath() + Path.GetRandomFileName();
            TestContext.Out.WriteLine("Using the Pki Root {0}", PkiRoot);

            // The parameters are read from the .runsettings file
            string customUrl = null;

            if (SupportsExternalServerUrl)
            {
                customUrl = TestContext.Parameters["ServerUrl"];
                if (customUrl?.StartsWith(UriScheme, StringComparison.Ordinal) == true)
                {
                    TestContext.Out.WriteLine("Using the external Server Url {0}", customUrl);

                    // load custom test sets
                    TestSetStatic     = ReadCustomTestSet("TestSetStatic");
                    TestSetSimulation = ReadCustomTestSet("TestSetSimulation");
                }
                else
                {
                    customUrl = null;
                }
            }

            if (customUrl == null)
            {
                // start Ref server
                ServerFixture = new ServerFixture <ReferenceServer> {
                    UriScheme       = UriScheme,
                    SecurityNone    = true,
                    AutoAccept      = true,
                    AllNodeManagers = true,
                    OperationLimits = true
                };

                if (writer != null)
                {
                    ServerFixture.TraceMasks = Utils.TraceMasks.Error | Utils.TraceMasks.Security;
                }

                await ServerFixture.LoadConfiguration(PkiRoot).ConfigureAwait(false);

                ServerFixture.Config.TransportQuotas.MaxMessageSize      =
                    ServerFixture.Config.TransportQuotas.MaxBufferSize   = TransportQuotaMaxMessageSize;
                ServerFixture.Config.TransportQuotas.MaxByteStringLength =
                    ServerFixture.Config.TransportQuotas.MaxStringLength = TransportQuotaMaxStringLength;
                ServerFixture.Config.ServerConfiguration.UserTokenPolicies.Add(
                    new UserTokenPolicy(UserTokenType.IssuedToken)
                {
                    IssuedTokenType = Opc.Ua.Profiles.JwtUserToken
                });

                ReferenceServer = await ServerFixture.StartAsync(writer ?? TestContext.Out).ConfigureAwait(false);

                ReferenceServer.TokenValidator = this.TokenValidator;
            }

            ClientFixture = new ClientFixture();
            await ClientFixture.LoadClientConfiguration(PkiRoot).ConfigureAwait(false);

            ClientFixture.Config.TransportQuotas.MaxMessageSize      =
                ClientFixture.Config.TransportQuotas.MaxBufferSize   = TransportQuotaMaxMessageSize;
            ClientFixture.Config.TransportQuotas.MaxByteStringLength =
                ClientFixture.Config.TransportQuotas.MaxStringLength = TransportQuotaMaxStringLength;

            if (!string.IsNullOrEmpty(customUrl))
            {
                ServerUrl = new Uri(customUrl);
            }
            else
            {
                ServerUrl = new Uri(UriScheme + "://localhost:" + ServerFixture.Port.ToString(CultureInfo.InvariantCulture));
            }

            if (SingleSession)
            {
                try
                {
                    Session = await ClientFixture.ConnectAsync(ServerUrl, SecurityPolicies.Basic256Sha256).ConfigureAwait(false);
                }
                catch (Exception e)
                {
                    Assert.Ignore("OneTimeSetup failed to create session, tests skipped. Error: {0}", e.Message);
                }
            }
        }