public void ObfuscateIpFact(string input, string expectedOutput)
        {
            // Arrange & Act
            var output = Obfuscator.ObfuscateIp(input);

            // Assert
            Assert.Equal(expectedOutput, output);
        }
예제 #2
0
        public static Task <AuditActor> GetAspNetOnBehalfOfAsync(HttpContextBase context)
        {
            // Try to identify the client IP using various server variables
            var clientIpAddress = context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

            if (string.IsNullOrEmpty(clientIpAddress)) // Try REMOTE_ADDR server variable
            {
                clientIpAddress = context.Request.ServerVariables["REMOTE_ADDR"];
            }

            if (string.IsNullOrEmpty(clientIpAddress)) // Try UserHostAddress property
            {
                clientIpAddress = context.Request.UserHostAddress;
            }

            clientIpAddress = Obfuscator.ObfuscateIp(clientIpAddress);

            string user          = null;
            string authType      = null;
            string credentialKey = null;

            if (context.User != null)
            {
                user     = context.User.Identity.Name;
                authType = context.User.Identity.AuthenticationType;

                var claimsIdentity = context.User.Identity as ClaimsIdentity;
                credentialKey = claimsIdentity?.GetClaimOrDefault(NuGetClaims.CredentialKey);
            }

            return(Task.FromResult(new AuditActor(
                                       null,
                                       clientIpAddress,
                                       user,
                                       authType,
                                       credentialKey,
                                       DateTime.UtcNow)));
        }