private Task <SecurityPolicyResult> EvaluateAsync(string minProtocolVersions, string actualClientVersion, string actualProtocolVersion)
        {
            var headers = new NameValueCollection();

            if (!string.IsNullOrEmpty(actualClientVersion))
            {
                headers[Constants.ClientVersionHeaderName] = actualClientVersion;
            }

            if (!string.IsNullOrEmpty(actualProtocolVersion))
            {
                headers[Constants.NuGetProtocolHeaderName] = actualProtocolVersion;
            }

            var httpRequest = new Mock <HttpRequestBase>();

            httpRequest.Setup(r => r.Headers).Returns(headers);

            var httpContext = new Mock <HttpContextBase>();

            httpContext.Setup(c => c.Request).Returns(httpRequest.Object);

            var policies = minProtocolVersions.Split(',').Select(
                v => RequireMinProtocolVersionForPushPolicy.CreatePolicy("Subscription", new NuGetVersion(v))
                ).ToArray();
            var context = new UserSecurityPolicyEvaluationContext(policies, httpContext.Object);

            return(new RequireMinProtocolVersionForPushPolicy().EvaluateAsync(context));
        }
コード例 #2
0
 private static List <UserSecurityPolicy> InitializePoliciesList()
 {
     return(new List <UserSecurityPolicy>()
     {
         new UserSecurityPolicy(RequirePackageVerifyScopePolicy.PolicyName, Name),
         RequireMinProtocolVersionForPushPolicy.CreatePolicy(Name, new NuGetVersion(MinProtocolVersion))
     });
 }