Ejemplo n.º 1
0
        public void Transform_uuid_ToGuid()
        {
            // Arrange
            Mock <ILogger <TokenTransformer> > logger = new Mock <ILogger <TokenTransformer> >();
            ITokenTransformer transformer             = new TokenTransformer(logger.Object);

            // Act
            string transformed = transformer.Transform("I am a {0}", new List <Token> {
                new UuidToken()
            }, new Random(), null);

            // Assert
            string uuid = transformed.Substring(7);
            Guid   guid;

            Assert.True(Guid.TryParse(uuid, out guid));
        }
Ejemplo n.º 2
0
        public void Transform_utcnow_ToUtcNow()
        {
            // Arrange
            UtcNowToken token = new UtcNowToken();
            Mock <ILogger <TokenTransformer> > logger = new Mock <ILogger <TokenTransformer> >();
            ITokenTransformer transformer             = new TokenTransformer(logger.Object);

            // Act
            string transformed = transformer.Transform("I am a {0}", new List <Token> {
                token
            }, new Random(), null);

            // Assert
            string   value = transformed.Substring(7);
            DateTime dateTime;

            Assert.True(DateTime.TryParse(value, out dateTime));
        }
Ejemplo n.º 3
0
        public void Transform_StringWithQuotes_CorrectlyFormated()
        {
            // Arrange
            Token token = new UuidToken();
            Mock <ILogger <TokenTransformer> > logger = new Mock <ILogger <TokenTransformer> >();
            ITokenTransformer transformer             = new TokenTransformer(logger.Object);

            // Act
            string transformed = transformer.Transform("{{\"Hello\":\"{0}\"}}", new List <Token> {
                token
            }, new Random(), null);

            // Assert
            string uuid = transformed.Substring(10, transformed.Length - 12);
            Guid   guid;

            Assert.True(Guid.TryParse(uuid, out guid));
        }
Ejemplo n.º 4
0
        public void Transform_randomitem_ToRandomItemInArray()
        {
            // Arrange
            Token token = new RandomItemToken {
                Items = new [] { "Info", "Warn", "Error" }
            };
            Mock <ILogger <TokenTransformer> > logger = new Mock <ILogger <TokenTransformer> >();
            ITokenTransformer transformer             = new TokenTransformer(logger.Object);

            // Act
            string transformed = transformer.Transform("I am a {0}", new List <Token> {
                token
            }, new Random(), null);

            // Assert
            string logLevel = transformed.Substring(7);

            Assert.Contains(logLevel, new [] { "Info", "Warn", "Error" });
        }
Ejemplo n.º 5
0
        public void Transform_linefromfile_ToItemInArray()
        {
            // Arrange
            Token token = new LineFromFileToken
            {
                Items = new[] { "emerg", "alert", "crit", "error", "warn", "notice" }
            };
            Mock <ILogger <TokenTransformer> > logger = new Mock <ILogger <TokenTransformer> >();
            ITokenTransformer transformer             = new TokenTransformer(logger.Object);

            // Act
            string transformed = transformer.Transform("I am a {0}", new List <Token> {
                token
            }, new Random(), null);

            // Assert
            string logLevel = transformed.Substring(7);

            Assert.Contains(logLevel, new[] { "emerg", "alert", "crit", "error", "warn", "notice" });
        }
Ejemplo n.º 6
0
        public void Transform_randombetween_ToRandomNumberFromRange()
        {
            // Arrange
            Token token = new RandomBetweenToken
            {
                Lower = 1,
                Upper = 10
            };
            Mock <ILogger <TokenTransformer> > logger = new Mock <ILogger <TokenTransformer> >();
            ITokenTransformer transformer             = new TokenTransformer(logger.Object);

            // Act
            string transformed = transformer.Transform("I am a {0}", new List <Token> {
                token
            }, new Random(), null);

            // Assert
            string numberAsString = transformed.Substring(7);
            int    number;

            Assert.True(int.TryParse(numberAsString, out number));
            Assert.InRange <int>(number, 1, 10);
        }
Ejemplo n.º 7
0
        public void Transform_TemplateWithVariables_VariableUsed()
        {
            // Arrange
            Token token = new VariableToken("myid");
            Mock <ILogger <TokenTransformer> > logger = new Mock <ILogger <TokenTransformer> >();
            ITokenTransformer transformer             = new TokenTransformer(logger.Object);

            // Act
            string transformed = transformer.Transform(
                "{{\"Hello\":\"{0}\"}}",
                new List <Token> {
                token
            }, new Random(), new Dictionary <string, Extraction> {
                { "myid", new Extraction {
                      Template = "ABC", Tokens = new List <Token>()
                  } }
            });

            // Assert
            string id = transformed.Substring(10, transformed.Length - 12);

            Assert.Equal("ABC", id);
        }
Ejemplo n.º 8
0
    private string ObtainAndTransformSpineSaml()
    {
        // Fetch the SAML from the spine
        string spineSaml = this.DownloadSpineSaml(this.TokenId);

        if (spineSaml != null)
        {
            // Get the Spine error response settings from the configuration file.
            string sSpineErrorNodeXPath = GetApplicationSetting(
                Constants.APPKEY_SPINE_ERROR_NODE_XPATH, typeof(string), false);

            string sSpineErrorCodeXPath = GetApplicationSetting(
                Constants.APPKEY_SPINE_ERROR_CODE_XPATH, typeof(string), false);

            string sSpineErrorDescXPath = GetApplicationSetting(
                Constants.APPKEY_SPINE_ERROR_DESC_XPATH, typeof(string), false);

            // Log BEGIN_SAML_TRANSFORM timing trace point.
            if (Fujitsu.SamlBridge.Trace.s_trswSamlBridgeTiming.Enabled)
            {
                Fujitsu.SamlBridge.Trace.WriteLine(
                    this, Constants.TRCT_BEGIN_SAML_TRANSFORM);
            }

            // Transform the Spine SAML into ADFS (SAML 1.1) compliant SAML.
            string sAdfsSaml = TokenTransformer.Transform(
                spineSaml,
                this.FederationRealm,
                (string)s_appsr.GetValue(
                    Constants.APPKEY_ACCOUNT_URI, typeof(string)),
                (string)s_appsr.GetValue(
                    Constants.APPKEY_AUTHENTICATION_METHOD, typeof(string)),
                (string)s_appsr.GetValue(
                    Constants.APPKEY_ACCOUNT_SIGNING_CERTIFICATE, typeof(string)),
                (string)s_appsr.GetValue(
                    Constants.APPKEY_UID_XPATH, typeof(string)),
                (string)s_appsr.GetValue(
                    Constants.APPKEY_ATTRIBUTES_ROOT_XPATH, typeof(string)),
                (long)s_appsr.GetValue(
                    Constants.APPKEY_TOKEN_LIFETIME_IN_SECONDS, typeof(long)),
                sSpineErrorNodeXPath,
                sSpineErrorCodeXPath,
                sSpineErrorDescXPath);

            // Log END_SAML_TRANSFORM timing trace point.
            if (Fujitsu.SamlBridge.Trace.s_trswSamlBridgeTiming.Enabled)
            {
                Fujitsu.SamlBridge.Trace.WriteLine(
                    this, Constants.TRCT_END_SAML_TRANSFORM);
            }

            if (Fujitsu.SamlBridge.Trace.s_trswSamlBridgePath.TraceInfo)
            {
                Fujitsu.SamlBridge.Trace.WriteLine(
                    this, Constants.TRCI_ADFS_SAML, sAdfsSaml);
            }

            return(sAdfsSaml);
        }
        else
        {
            /* We were unable to contact the spine, so we are now in failover mode 2. We
             * therefore invoke decoupled operation by transferring control to
             * SamlBridgeDecoupled.aspx. */
            if (Fujitsu.SamlBridge.Trace.s_trswSamlBridgePath.TraceInfo)
            {
                Fujitsu.SamlBridge.Trace.WriteLine(
                    this, Constants.TRCI_TRANSFERRING_TO_DECOUPLED_PAGE);
            }

            Server.Transfer(Constants.ASPX_SAML_BRIDGE_DECOUPLED, true);
            return(null);
        }
    }