public void LoginWithOwnerUsernameAndPasswordSuccessfully() { var expectedSettings = new AuthenticationSettings { UserAuthentication = true, UsePassword = true, PlexAuthToken = "abc" }; var plexFriends = new PlexFriends { User = new[] { new UserFriends() } }; var plexAuth = new PlexAuthentication { user = new User { authentication_token = "abc", username = "******" } }; var account = new PlexAccount { Username = "******" }; AuthMock.Setup(x => x.GetSettings()).Returns(expectedSettings); PlexMock.Setup(x => x.GetUsers(It.IsAny <string>())).Returns(plexFriends); PlexMock.Setup(x => x.SignIn(It.IsAny <string>(), It.IsAny <string>())).Returns(plexAuth); PlexMock.Setup(x => x.GetAccount(It.IsAny <string>())).Returns(account); var bootstrapper = new ConfigurableBootstrapper(with => { with.Module <UserLoginModule>(); with.Dependency(AuthMock.Object); with.Dependency(PlexMock.Object); with.RootPathProvider <TestRootPathProvider>(); }); bootstrapper.WithSession(new Dictionary <string, object>()); var browser = new Browser(bootstrapper); var result = browser.Post("/userlogin", with => { with.HttpRequest(); with.Header("Accept", "application/json"); with.FormValue("Username", "jamie"); with.FormValue("Password", "abc"); }); Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode)); Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.EqualTo("jamie")); var body = JsonConvert.DeserializeObject <JsonResponseModel>(result.Body.AsString()); Assert.That(body.Result, Is.EqualTo(true)); AuthMock.Verify(x => x.GetSettings(), Times.Once); PlexMock.Verify(x => x.SignIn(It.IsAny <string>(), It.IsAny <string>()), Times.Once); PlexMock.Verify(x => x.GetUsers(It.IsAny <string>()), Times.Never); }
public void LoginWithoutAuthenticationWithEmptyUsername() { var expectedSettings = new AuthenticationSettings { UserAuthentication = false, PlexAuthToken = "abc" }; AuthMock.Setup(x => x.GetSettings()).Returns(expectedSettings); var bootstrapper = new ConfigurableBootstrapper(with => { with.Module <UserLoginModule>(); with.Dependency(AuthMock.Object); with.Dependency(PlexMock.Object); with.RootPathProvider <TestRootPathProvider>(); }); bootstrapper.WithSession(new Dictionary <string, object>()); var browser = new Browser(bootstrapper); var result = browser.Post("/userlogin", with => { with.HttpRequest(); with.Header("Accept", "application/json"); with.FormValue("Username", string.Empty); }); Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode)); var body = JsonConvert.DeserializeObject <JsonResponseModel>(result.Body.AsString()); Assert.That(body.Result, Is.EqualTo(false)); AuthMock.Verify(x => x.GetSettings(), Times.Never); PlexMock.Verify(x => x.SignIn(It.IsAny <string>(), It.IsAny <string>()), Times.Never); PlexMock.Verify(x => x.GetUsers(It.IsAny <string>()), Times.Never); }
public void HandlesAuthorization() { // Mismatched CSRF token bootstrapper.WithSession(new Dictionary <string, object> { { "CSRF:State", "sometoken" }, }); var result = this.browser.Get("/authorize", (with) => { with.HttpRequest(); with.Query("state", "someothertoken"); }); Assert.AreEqual(HttpStatusCode.Unauthorized, result.StatusCode); // Matching CSRF token bootstrapper.WithSession(new Dictionary <string, object> { { "CSRF:State", "sometoken" }, { "OrigUrl", "http://success" }, }); result = this.browser.Get("/authorize", (with) => { with.HttpRequest(); with.Query("state", "sometoken"); }); result.ShouldHaveRedirectedTo("/authorize/success"); }
public void Logout() { var bootstrapper = new ConfigurableBootstrapper(with => { with.Module <UserLoginModule>(); with.Dependency(AuthMock.Object); with.Dependency(PlexMock.Object); with.RootPathProvider <TestRootPathProvider>(); }); bootstrapper.WithSession(new Dictionary <string, object> { { SessionKeys.UsernameKey, "abc" } }); var browser = new Browser(bootstrapper); var result = browser.Get("/userlogin/logout", with => { with.HttpRequest(); with.Header("Accept", "application/json"); }); Assert.That(HttpStatusCode.SeeOther, Is.EqualTo(result.StatusCode)); Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.Null); }
public void Setup() { AuthMock = new Mock <ISettingsService <AuthenticationSettings> >(); var expectedSettings = new AuthenticationSettings { UserAuthentication = false }; AuthMock.Setup(x => x.GetSettings()).Returns(expectedSettings); PlexSettingsMock = new Mock <ISettingsService <PlexSettings> >(); PlexSettingsMock.Setup(x => x.GetSettings()).Returns(new PlexSettings { PlexAuthToken = "abc" }); PlexMock = new Mock <IPlexApi>(); PlexMock.Setup(x => x.SignIn("Username1", "Password1")) .Returns(new PlexAuthentication { user = new User { authentication_token = "abc", title = "Username1" } }); PlexRequestMock = new Mock <ISettingsService <PlexRequestSettings> >(); PlexRequestMock.Setup(x => x.GetSettings()).Returns(new PlexRequestSettings()); CpMock = new Mock <ISettingsService <CouchPotatoSettings> >(); SonarrApiMock = new Mock <ISonarrApi>(); SonarrSettingsMock = new Mock <ISettingsService <SonarrSettings> >(); EmailMock = new Mock <ISettingsService <EmailNotificationSettings> >(); PushbulletApi = new Mock <IPushbulletApi>(); PushbulletSettings = new Mock <ISettingsService <PushbulletNotificationSettings> >(); CpApi = new Mock <ICouchPotatoApi>(); SickRageSettingsMock = new Mock <ISettingsService <SickRageSettings> >(); LogRepo = new Mock <IRepository <LogEntity> >(); PushoverSettings = new Mock <ISettingsService <PushoverNotificationSettings> >(); PushoverApi = new Mock <IPushoverApi>(); NotificationService = new Mock <INotificationService>(); HeadphonesSettings = new Mock <ISettingsService <HeadphonesSettings> >(); Cache = new Mock <ICacheProvider>(); Log = new Mock <ISettingsService <LogSettings> >(); SlackApi = new Mock <ISlackApi>(); SlackSettings = new Mock <ISettingsService <SlackNotificationSettings> >(); LandingPageSettings = new Mock <ISettingsService <LandingPageSettings> >(); ScheduledJobsSettingsMock = new Mock <ISettingsService <ScheduledJobsSettings> >(); RecorderMock = new Mock <IJobRecord>(); Analytics = new Mock <IAnalytics>(); NotifyV2 = new Mock <ISettingsService <NotificationSettingsV2> >(); RecentlyAdded = new Mock <IRecentlyAdded>(); Bootstrapper = new ConfigurableBootstrapper(with => { with.Module <AdminModule>(); with.Dependency(AuthMock.Object); with.Dependency(PlexRequestMock.Object); with.Dependency(CpMock.Object); with.Dependency(PlexSettingsMock.Object); with.Dependency(SonarrApiMock.Object); with.Dependency(SonarrSettingsMock.Object); with.Dependency(PlexMock.Object); with.Dependency(EmailMock.Object); with.Dependency(PushbulletApi.Object); with.Dependency(PushbulletSettings.Object); with.Dependency(CpApi.Object); with.Dependency(SickRageSettingsMock.Object); with.Dependency(LogRepo.Object); with.Dependency(PushoverSettings.Object); with.Dependency(PushoverApi.Object); with.Dependency(NotifyV2.Object); with.Dependency(NotificationService.Object); with.Dependency(Analytics.Object); with.Dependency(HeadphonesSettings.Object); with.Dependency(Cache.Object); with.Dependency(Log.Object); with.Dependency(SlackApi.Object); with.Dependency(LandingPageSettings.Object); with.Dependency(SlackSettings.Object); with.Dependency(ScheduledJobsSettingsMock.Object); with.Dependency(RecorderMock.Object); with.Dependency(RecentlyAdded.Object); with.RootPathProvider <TestRootPathProvider>(); with.RequestStartup((container, pipelines, context) => { context.CurrentUser = new UserIdentity { UserName = "******", Claims = new List <string> { "Admin" } }; }); }); Bootstrapper.WithSession(new Dictionary <string, object>()); }