Beispiel #1
0
        public IEnumerator GetUserInfoAsync_JsonParseFailed_ReturnsNull()
        {
            LearningLayersOidcProvider lloidc        = new LearningLayersOidcProvider();
            IRestConnector             restConnector = A.Fake <IRestConnector>();

            A.CallTo(() => restConnector.GetAsync(A <string> .Ignored))
            .Returns(new WebResponse <string>("answer", null, 200));
            lloidc.RestConnector = restConnector;
            LearningLayersUserInfo userInfo   = new LearningLayersUserInfo("tester", "*****@*****.**", "Tester");
            IJsonSerializer        serializer = A.Fake <IJsonSerializer>();

            A.CallTo(() => serializer.FromJson <LearningLayersUserInfo>(A <string> .Ignored))
            .Returns(null);
            lloidc.JsonSerializer = serializer;

            LogAssert.Expect(LogType.Error, new Regex(@"\w*Could not parse user info\w*"));

            Task <IUserInfo> task = lloidc.GetUserInfoAsync("");

            yield return(AsyncTest.WaitForTask(task));

            IUserInfo res = task.Result;

            Assert.IsNull(res);
        }
Beispiel #2
0
        public IEnumerator GetAccessCodeFromTokenAsync_WebResponseSuccess_ReturnsToken()
        {
            LearningLayersOidcProvider lloidc        = new LearningLayersOidcProvider();
            IRestConnector             restConnector = A.Fake <IRestConnector>();

            A.CallTo(() => restConnector.PostAsync(A <string> .Ignored, A <string> .Ignored))
            .Returns(Task.FromResult(new WebResponse <string>("json string", null, 200)));
            lloidc.RestConnector = restConnector;
            lloidc.ClientData    = A.Fake <ClientData>();
            LearningLayersAuthorizationFlowAnswer answer = new LearningLayersAuthorizationFlowAnswer();

            answer.access_token = "myAccessToken";
            IJsonSerializer serializer = A.Fake <IJsonSerializer>();

            A.CallTo(() => serializer.FromJson <LearningLayersAuthorizationFlowAnswer>(A <string> .Ignored))
            .Returns(answer);
            lloidc.JsonSerializer = serializer;

            Task <string> task = lloidc.GetAccessTokenFromCodeAsync("", "");

            yield return(AsyncTest.WaitForTask(task));

            string res = task.Result;

            Assert.AreEqual(answer.access_token, res);
        }
Beispiel #3
0
        public void ParametersContainError_NoError_ErrorMessageEmpty()
        {
            LearningLayersOidcProvider  lloidc             = new LearningLayersOidcProvider();
            Dictionary <string, string> redirectParameters = new Dictionary <string, string>();

            bool res = lloidc.ParametersContainError(redirectParameters, out string message);

            Assert.IsEmpty(message);
        }
Beispiel #4
0
        public void GetAuthorizationCode_CodeProvided_ExtractsCode()
        {
            LearningLayersOidcProvider  lloidc             = new LearningLayersOidcProvider();
            Dictionary <string, string> redirectParameters = new Dictionary <string, string>();

            redirectParameters.Add("code", "myCode");
            string res = lloidc.GetAuthorizationCode(redirectParameters);

            Assert.AreEqual("myCode", res);
        }
Beispiel #5
0
        public void GetAccessToken_TokenProvided_ExtractsToken()
        {
            LearningLayersOidcProvider  lloidc             = new LearningLayersOidcProvider();
            Dictionary <string, string> redirectParameters = new Dictionary <string, string>();

            redirectParameters.Add("token", "myAccessToken");

            string res = lloidc.GetAccessToken(redirectParameters);

            Assert.AreEqual("myAccessToken", res);
        }
Beispiel #6
0
        public void GetAuthorizationCode_CodeNotProvided_ReturnsEmptyString()
        {
            LearningLayersOidcProvider  lloidc             = new LearningLayersOidcProvider();
            Dictionary <string, string> redirectParameters = new Dictionary <string, string>();

            LogAssert.Expect(LogType.Error, new Regex(@"\w*Redirect parameters did not contain authorization code\w*"));

            string res = lloidc.GetAuthorizationCode(redirectParameters);

            Assert.IsEmpty(res);
        }
Beispiel #7
0
        public void ParametersContainError_ErrorGiven_ReturnsTrue()
        {
            LearningLayersOidcProvider  lloidc             = new LearningLayersOidcProvider();
            Dictionary <string, string> redirectParameters = new Dictionary <string, string>();

            redirectParameters.Add("error", "This is a simulated error");

            bool res = lloidc.ParametersContainError(redirectParameters, out string message);

            Assert.IsTrue(res);
        }
Beispiel #8
0
        public void GetAccessToken_TokenNotProvided_ReturnsEmptyToken()
        {
            LearningLayersOidcProvider  lloidc             = new LearningLayersOidcProvider();
            Dictionary <string, string> redirectParameters = new Dictionary <string, string>();

            LogAssert.Expect(LogType.Error, new Regex(@"\w*Redirect parameters did not contain access token\w*"));

            string res = lloidc.GetAccessToken(redirectParameters);

            Assert.IsEmpty(res);
        }
Beispiel #9
0
        public void ParametersContainError_ErrorGiven_ErrorMessageSet()
        {
            LearningLayersOidcProvider  lloidc             = new LearningLayersOidcProvider();
            Dictionary <string, string> redirectParameters = new Dictionary <string, string>();
            string errorMsg = "This is a simulated error";

            redirectParameters.Add("error", errorMsg);

            bool res = lloidc.ParametersContainError(redirectParameters, out string message);

            Assert.AreEqual(errorMsg, message);
        }
Beispiel #10
0
        public void OpenLoginPage_UriGiven_BrowserOpened()
        {
            LearningLayersOidcProvider lloidc = new LearningLayersOidcProvider();
            IBrowser browser = A.Fake <IBrowser>();

            lloidc.Browser    = browser;
            lloidc.ClientData = A.Fake <ClientData>();
            string[] testScopes = new string[] { "testScope" };

            lloidc.OpenLoginPage(testScopes, "http://www.test.com");

            A.CallTo(() => browser.OpenURL(A <string> .That.Contains("http://www.test.com"))).MustHaveHappenedOnceExactly();
            A.CallTo(() => browser.OpenURL(A <string> .That.Contains("testScope"))).MustHaveHappenedOnceExactly();
        }
        // Update is called once per frame
        private void Update()
        {
            if (Input.GetKeyDown(KeyCode.F5))
            {
                LearningLayersOidcProvider provider = new LearningLayersOidcProvider();
                provider.ClientData = learningLayersClientData.clientData;
                ServiceManager.GetService <OpenIDConnectService>().OidcProvider = provider;

                // only subscribe to the event if it was not yet done before, e.g. in a failed login attempt
                if (!isSubscribedToOidc)
                {
                    ServiceManager.GetService <OpenIDConnectService>().LoginCompleted += OpenIDConnectTester_LoginCompleted;
                    isSubscribedToOidc = true;
                }
                ServiceManager.GetService <OpenIDConnectService>().OpenLoginPage();
            }
        }
Beispiel #12
0
        public IEnumerator GetAccessCodeFromTokenAsync_NoClientData_ReturnsEmptyString()
        {
            LearningLayersOidcProvider lloidc = new LearningLayersOidcProvider();

            lloidc.RestConnector = A.Fake <IRestConnector>();

            LogAssert.Expect(LogType.Error,
                             new Regex(@"\w*No client data supplied for the OpenID Connect Client\w*"));

            Task <string> task = lloidc.GetAccessTokenFromCodeAsync("", "");

            yield return(AsyncTest.WaitForTask(task));

            string res = task.Result;

            Assert.IsEmpty(res);
        }
Beispiel #13
0
        public IEnumerator CheckAccessTokenAsync_WebResponseFailed_ReturnsFalse()
        {
            LearningLayersOidcProvider lloidc        = new LearningLayersOidcProvider();
            IRestConnector             restConnector = A.Fake <IRestConnector>();

            A.CallTo(() => restConnector.GetAsync(A <string> .Ignored))
            .Returns(new WebResponse <string>("This is a simulated error", 400));
            lloidc.RestConnector = restConnector;

            LogAssert.Expect(LogType.Error, new Regex(@"\w*This is a simulated error\w*"));

            Task <bool> task = lloidc.CheckAccessTokenAsync("");

            yield return(AsyncTest.WaitForTask(task));

            bool res = task.Result;

            Assert.IsFalse(res);
        }
Beispiel #14
0
        public IEnumerator GetAccessCodeFromTokenAsync_WebResponseFailed_ReturnsEmptyToken()
        {
            LearningLayersOidcProvider lloidc        = new LearningLayersOidcProvider();
            IRestConnector             restConnector = A.Fake <IRestConnector>();

            A.CallTo(() => restConnector.PostAsync(A <string> .Ignored, A <string> .Ignored))
            .Returns(Task.FromResult(new WebResponse <string>("my error", 400)));
            lloidc.RestConnector  = restConnector;
            lloidc.ClientData     = A.Fake <ClientData>();
            lloidc.JsonSerializer = A.Fake <IJsonSerializer>();

            LogAssert.Expect(LogType.Error,
                             new Regex(@"\w*my error\w*"));

            Task <string> task = lloidc.GetAccessTokenFromCodeAsync("", "");

            yield return(AsyncTest.WaitForTask(task));

            string res = task.Result;

            Assert.IsEmpty(res);
        }
Beispiel #15
0
        public IEnumerator CheckAccessTokenAsync_WebResponseSuccessful_ReturnsTrue()
        {
            LearningLayersOidcProvider lloidc        = new LearningLayersOidcProvider();
            IRestConnector             restConnector = A.Fake <IRestConnector>();

            A.CallTo(() => restConnector.GetAsync(A <string> .Ignored))
            .Returns(new WebResponse <string>("answer", null, 200));
            lloidc.RestConnector = restConnector;
            LearningLayersUserInfo userInfo   = new LearningLayersUserInfo("tester", "*****@*****.**", "Tester");
            IJsonSerializer        serializer = A.Fake <IJsonSerializer>();

            A.CallTo(() => serializer.FromJson <LearningLayersUserInfo>(A <string> .Ignored))
            .Returns(userInfo);
            lloidc.JsonSerializer = serializer;

            Task <bool> task = lloidc.CheckAccessTokenAsync("");

            yield return(AsyncTest.WaitForTask(task));

            bool res = task.Result;

            Assert.IsTrue(res);
        }
Beispiel #16
0
        public void Constructor_Initialized_ContentLoaderNotNull()
        {
            LearningLayersOidcProvider lloidc = new LearningLayersOidcProvider();

            Assert.IsNotNull(lloidc.RestConnector);
        }
Beispiel #17
0
        public void Constructor_Initialized_JsonWrapperNotNull()
        {
            LearningLayersOidcProvider lloidc = new LearningLayersOidcProvider();

            Assert.IsNotNull(lloidc.JsonSerializer);
        }