Пример #1
0
        public static ClientMocker ToRequestMocker(this HrbcVersion version)
        {
            var mock = new Mock <HttpClientHandler>();

            return(new ClientMocker(mock, PrivateClient.CreateClient(new PrivateServerSettings {
                HttpClientHandlerFactory = () => mock.Object, Version = version, AutoDetectVersion = false, LoggerFactory = TestLoggerFactoryAttribute.CurrentLoggerFactory
            })));
        }
Пример #2
0
        private bool IsVersionMatch(ITest test)
        {
            // get current version
            var versionStr = TestContext.Parameters.Get("HrbcVersion", string.Empty);

            if (versionStr == string.Empty)
            {
                return(true);
            }
            var version = HrbcVersion.Parse(versionStr);

            var bugs = new List <string>();

            ITest pointer = test;

            do
            {
                if (pointer.Properties.ContainsKey(BugAttribute.PropertyName))
                {
                    foreach (var entry in pointer.Properties[BugAttribute.PropertyName])
                    {
                        bugs.Add(entry.ToString());
                    }
                }
            } while (null != (pointer = pointer.Parent));

            foreach (var bug in bugs)
            {
                var bugSpec = bug.Split(':');
                var from    = bugSpec.Length > 1 ? bugSpec[1] : string.Empty;
                var until   = bugSpec.Length > 2 ? bugSpec[2] : string.Empty;

                bool isFrom  = from == string.Empty || HrbcVersion.Parse(from).CompareTo(version) <= 0;
                bool isUntil = until == string.Empty || HrbcVersion.Parse(until).CompareTo(version) > 0;

                if (isFrom && isUntil)
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #3
0
 public void LeftIsLess(string left, string right)
 {
     Assert.That(HrbcVersion.Parse(left), Is.LessThan(HrbcVersion.Parse(right)));
 }
Пример #4
0
 public void LeftIsGreater(string left, string right)
 {
     Assert.That(HrbcVersion.Parse(left), Is.GreaterThan(HrbcVersion.Parse(right)));
 }
Пример #5
0
 public void TrunkIsNotCaseSensitive(string version)
 {
     Assert.That(HrbcVersion.Parse(version).ToNormalisedString(), Is.EqualTo("trunk"));
 }
Пример #6
0
 public void UnderscoreSuffixIgnored(string version, string expected)
 {
     Assert.That(HrbcVersion.Parse(version).ToNormalisedString(), Is.EqualTo(expected));
 }
Пример #7
0
 public void IsSameAsInputOnValid(string version)
 {
     Assert.That(HrbcVersion.Parse(version).ToString(), Is.EqualTo(version));
 }
Пример #8
0
 public void InvalidSectionAreZeroed(string version, string expected)
 {
     Assert.That(HrbcVersion.Parse(version).ToNormalisedString(), Is.EqualTo(expected));
 }
Пример #9
0
 public void AreEqual(string left, string right)
 {
     Assert.That(HrbcVersion.Parse(left), Is.LessThanOrEqualTo(HrbcVersion.Parse(right)));
     Assert.That(HrbcVersion.Parse(left), Is.GreaterThanOrEqualTo(HrbcVersion.Parse(right)));
 }
Пример #10
0
        private AuthResponseCode RunAuthorizationProcess(string appId, string redirectUrl, string scope, PrivateAuthentication privateApiAuthData, string code = "code")
        {
            ResultOauthCode   = null;
            SubscriptionTrace = SubscriptionStep.NotStarted;
            var publicApiServerUri = new Uri(TestConfig.GetValueFromConfig("PublicServer"));
            var webServerUrl       = new Uri(TestConfig.GetValueFromConfig("BaseURI"));
            var cookiesCollector   = new Dictionary <string, string>();

            Log("Initialising Autherisation Process");
            var response = SendRequest(new Uri(publicApiServerUri, OverrideInitialRelativeUrl ?? string.Format(InitialRelativeUrlTemplate, appId, redirectUrl, scope, code)),
                                       cookiesCollector, null, null);

            SubscriptionTrace |= SubscriptionStep.FirstOauthReqeust;
            var errorCode = CheckErrors(response.Headers.Location, response, redirectUrl);

            if (errorCode.HasValue)
            {
                response.Dispose();
                return(errorCode.Value);
            }

            var memcacheSessionId   = OverrideMemcacheSessionCookie ?? cookiesCollector["jmemcachedsessionid"];
            var secondStepUrlEnding = response.Headers.Location.PathAndQuery;

            response.Dispose();

            Uri thirdStepUrl = null;

            if (privateApiAuthData.Session == null)
            {
                Log("2nd stage. No session, do manual login");
                thirdStepUrl       = DoManualLogin(privateApiAuthData.Company, privateApiAuthData.Username, privateApiAuthData.Password, cookiesCollector, publicApiServerUri, new Uri(webServerUrl, secondStepUrlEnding));
                SubscriptionTrace |= SubscriptionStep.ManualLogin;
                errorCode          = CheckErrors(thirdStepUrl, null, redirectUrl);
                if (errorCode.HasValue)
                {
                    return(errorCode.Value);
                }
            }
            else
            {
                Log("2nd stage. Use existing session.");
                var version       = GetVersion(privateApiAuthData);
                var useLoginToken = version.CompareTo(HrbcVersion.Parse("3.12.23")) >= 0;
                Log($"HRBC Version {version}. UseLoginToken={useLoginToken}.");
                response = SendRequest(new Uri(webServerUrl, secondStepUrlEnding), useLoginToken
                    ? new Dictionary <string, string> {
                    ["HRBCAUTH"] = privateApiAuthData.Session
                }
                    : new Dictionary <string, string> {
                    ["PHPSESSID"] = privateApiAuthData.Session, ["HRBCACCOUNT"] = privateApiAuthData.Account
                }, null, null);

                errorCode = CheckErrors(response.Headers.Location, response, redirectUrl);
                if (errorCode.HasValue)
                {
                    response.Dispose();
                    return(errorCode.Value);
                }

                thirdStepUrl = new Uri(publicApiServerUri, response.Headers.Location.PathAndQuery);
                response.Dispose();
            }

            if (!SkipAuthorisationConfirmation)
            {
                if (AuthSessionUrlQueryCustomisation != null && thirdStepUrl.Query.Contains("session="))
                {
                    thirdStepUrl = new Uri(new string(thirdStepUrl.AbsoluteUri.TakeWhile(x => x != '?').ToArray()) + AuthSessionUrlQueryCustomisation(thirdStepUrl.Query));
                }

                Log("Auth confimation");
                response = SendRequest(thirdStepUrl, new Dictionary <string, string> {
                    ["jmemcachedsessionid"] = memcacheSessionId
                }, null, null);
                SubscriptionTrace |= SubscriptionStep.AuthorisationConfirmation;

                errorCode = CheckErrors(response.Headers.Location, response, redirectUrl, false);
                response.Dispose();
                if (errorCode.HasValue)
                {
                    return(errorCode.Value);
                }
            }

            Log("Finalise");
            response = SendRequest(new Uri(publicApiServerUri, "/v1/authorization"), new Dictionary <string, string> {
                ["jmemcachedsessionid"] = memcacheSessionId
            }, null, DenyAuthorizaton ? "permission=deny" : "permission=accept");
            SubscriptionTrace |= SubscriptionStep.AuthorisationConfirmationChoiseMade;
            errorCode          = CheckErrors(response.Headers.Location, response, redirectUrl);
            response.Dispose();
            if (errorCode.HasValue)
            {
                return(errorCode.Value);
            }

            return(AuthResponseCode.Success);
        }
Пример #11
0
        private CookieContainer NewCookieContainer()
        {
            var collection = new CookieContainer();

            if (Parameters.Session != null)
            {
                collection.Add(Client.ServerSettings.ServerUrl, new Cookie(Client.ServerSettings.Version.CompareTo(HrbcVersion.Parse("3.12.23")) < 1 ? "PHPSESSID" : "HRBCAUTH", Parameters.Session));
            }
            return(collection);
        }