public void RegisterOAuthClient() { // Arrange var clients = new BuiltInOAuthClient[] { BuiltInOAuthClient.Facebook, BuiltInOAuthClient.Twitter, BuiltInOAuthClient.LinkedIn, BuiltInOAuthClient.WindowsLive }; var clientNames = new string[] { "Facebook", "Twitter", "LinkedIn", "WindowsLive" }; for (int i = 0; i < clients.Length; i++) { // Act OAuthWebSecurity.RegisterOAuthClient(clients[i], "key", "secret"); var client = new Mock <IAuthenticationClient>(); client.Setup(c => c.ProviderName).Returns(clientNames[i]); // Assert Assert.Throws(typeof(ArgumentException), () => OAuthWebSecurity.RegisterClient(client.Object)); } }
public void LoginFailIfUserIsNotFound() { // Arrange var context = new Mock <HttpContextBase>(); OAuthWebSecurity.RegisterOAuthClient(BuiltInOAuthClient.Twitter, "consumerKey", "consumerSecrte"); var dataProvider = new Mock <IOpenAuthDataProvider>(); dataProvider.Setup(p => p.GetUserNameFromOpenAuth("twitter", "12345")).Returns((string)null); OAuthWebSecurity.OAuthDataProvider = dataProvider.Object; // Act bool successful = OAuthWebSecurity.LoginCore(context.Object, "twitter", "12345", createPersistentCookie: false); // Assert Assert.False(successful); }
public void LoginSetAuthenticationTicketIfSuccessful() { // Arrange var cookies = new HttpCookieCollection(); var context = new Mock <HttpContextBase>(); context.Setup(c => c.Request.IsSecureConnection).Returns(true); context.Setup(c => c.Response.Cookies).Returns(cookies); var dataProvider = new Mock <IOpenAuthDataProvider>(MockBehavior.Strict); dataProvider.Setup(p => p.GetUserNameFromOpenAuth("twitter", "12345")).Returns("hola"); OAuthWebSecurity.OAuthDataProvider = dataProvider.Object; OAuthWebSecurity.RegisterOAuthClient(BuiltInOAuthClient.Twitter, "sdfdsfsd", "dfdsfdsf"); // Act bool successful = OAuthWebSecurity.LoginCore(context.Object, "twitter", "12345", createPersistentCookie: false); // Assert Assert.True(successful); Assert.Equal(1, cookies.Count); HttpCookie addedCookie = cookies[0]; Assert.Equal(FormsAuthentication.FormsCookieName, addedCookie.Name); Assert.True(addedCookie.HttpOnly); Assert.Equal("/", addedCookie.Path); Assert.False(addedCookie.Secure); Assert.False(String.IsNullOrEmpty(addedCookie.Value)); FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(addedCookie.Value); Assert.NotNull(ticket); Assert.Equal(2, ticket.Version); Assert.Equal("hola", ticket.Name); Assert.Equal("OAuth", ticket.UserData); Assert.False(ticket.IsPersistent); }