mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-16 02:02:55 -07:00
More tests to cover the login
This commit is contained in:
parent
6926cfdda0
commit
92e8fa7c4d
2 changed files with 206 additions and 0 deletions
|
@ -104,6 +104,10 @@
|
||||||
<Project>{95834072-A675-415D-AA8F-877C91623810}</Project>
|
<Project>{95834072-A675-415D-AA8F-877C91623810}</Project>
|
||||||
<Name>PlexRequests.Api.Interfaces</Name>
|
<Name>PlexRequests.Api.Interfaces</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\PlexRequests.Api.Models\PlexRequests.Api.Models.csproj">
|
||||||
|
<Project>{CB37A5F8-6DFC-4554-99D3-A42B502E4591}</Project>
|
||||||
|
<Name>PlexRequests.Api.Models</Name>
|
||||||
|
</ProjectReference>
|
||||||
<ProjectReference Include="..\PlexRequests.Core\PlexRequests.Core.csproj">
|
<ProjectReference Include="..\PlexRequests.Core\PlexRequests.Core.csproj">
|
||||||
<Project>{DD7DC444-D3BF-4027-8AB9-EFC71F5EC581}</Project>
|
<Project>{DD7DC444-D3BF-4027-8AB9-EFC71F5EC581}</Project>
|
||||||
<Name>PlexRequests.Core</Name>
|
<Name>PlexRequests.Core</Name>
|
||||||
|
|
|
@ -36,6 +36,8 @@ using Newtonsoft.Json;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
using PlexRequests.Api.Interfaces;
|
using PlexRequests.Api.Interfaces;
|
||||||
|
using PlexRequests.Api.Models;
|
||||||
|
using PlexRequests.Api.Models.Tv;
|
||||||
using PlexRequests.Core;
|
using PlexRequests.Core;
|
||||||
using PlexRequests.Core.SettingModels;
|
using PlexRequests.Core.SettingModels;
|
||||||
using PlexRequests.UI.Models;
|
using PlexRequests.UI.Models;
|
||||||
|
@ -89,5 +91,205 @@ namespace PlexRequests.UI.Tests
|
||||||
Assert.That(body.Result, Is.EqualTo(true));
|
Assert.That(body.Result, Is.EqualTo(true));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void LoginWithUsernameSuccessfully()
|
||||||
|
{
|
||||||
|
var expectedSettings = new AuthenticationSettings { UserAuthentication = true, PlexAuthToken = "abc" };
|
||||||
|
var plexFriends = new PlexFriends
|
||||||
|
{
|
||||||
|
User = new[]
|
||||||
|
{
|
||||||
|
new UserFriends
|
||||||
|
{
|
||||||
|
Username = "abc",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
AuthMock.Setup(x => x.GetSettings()).Returns(expectedSettings);
|
||||||
|
PlexMock.Setup(x => x.GetUsers(It.IsAny<string>())).Returns(plexFriends);
|
||||||
|
|
||||||
|
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);
|
||||||
|
// When
|
||||||
|
var result = browser.Post("/userlogin", with =>
|
||||||
|
{
|
||||||
|
with.HttpRequest();
|
||||||
|
with.Header("Accept", "application/json");
|
||||||
|
with.FormValue("Username", "abc");
|
||||||
|
});
|
||||||
|
|
||||||
|
// Then
|
||||||
|
Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
||||||
|
Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.EqualTo("abc"));
|
||||||
|
|
||||||
|
var body = JsonConvert.DeserializeObject<JsonResponseModel>(result.Body.AsString());
|
||||||
|
Assert.That(body.Result, Is.EqualTo(true));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void LoginWithUsernameUnSuccessfully()
|
||||||
|
{
|
||||||
|
var expectedSettings = new AuthenticationSettings { UserAuthentication = true, PlexAuthToken = "abc" };
|
||||||
|
var plexFriends = new PlexFriends
|
||||||
|
{
|
||||||
|
User = new[]
|
||||||
|
{
|
||||||
|
new UserFriends
|
||||||
|
{
|
||||||
|
Username = "aaaa",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
AuthMock.Setup(x => x.GetSettings()).Returns(expectedSettings);
|
||||||
|
PlexMock.Setup(x => x.GetUsers(It.IsAny<string>())).Returns(plexFriends);
|
||||||
|
|
||||||
|
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", "abc");
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
||||||
|
Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.EqualTo("abc"));
|
||||||
|
|
||||||
|
var body = JsonConvert.DeserializeObject<JsonResponseModel>(result.Body.AsString());
|
||||||
|
Assert.That(body.Result, Is.EqualTo(false));
|
||||||
|
Assert.That(body.Message, Is.Not.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void LoginWithUsernameAndPasswordSuccessfully()
|
||||||
|
{
|
||||||
|
var expectedSettings = new AuthenticationSettings { UserAuthentication = true, UsePassword = true, PlexAuthToken = "abc" };
|
||||||
|
var plexFriends = new PlexFriends
|
||||||
|
{
|
||||||
|
User = new[]
|
||||||
|
{
|
||||||
|
new UserFriends
|
||||||
|
{
|
||||||
|
Username = "abc",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var plexAuth = new PlexAuthentication
|
||||||
|
{
|
||||||
|
user = new User
|
||||||
|
{
|
||||||
|
authentication_token = "abc"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
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);
|
||||||
|
// When
|
||||||
|
var result = browser.Post("/userlogin", with =>
|
||||||
|
{
|
||||||
|
with.HttpRequest();
|
||||||
|
with.Header("Accept", "application/json");
|
||||||
|
with.FormValue("Username", "abc");
|
||||||
|
with.FormValue("Password", "abc");
|
||||||
|
});
|
||||||
|
|
||||||
|
// Then
|
||||||
|
Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
||||||
|
Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.EqualTo("abc"));
|
||||||
|
|
||||||
|
var body = JsonConvert.DeserializeObject<JsonResponseModel>(result.Body.AsString());
|
||||||
|
Assert.That(body.Result, Is.EqualTo(true));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void LoginWithUsernameAndPasswordUnSuccessfully()
|
||||||
|
{
|
||||||
|
var expectedSettings = new AuthenticationSettings { UserAuthentication = true, UsePassword = true, PlexAuthToken = "abc" };
|
||||||
|
var plexFriends = new PlexFriends
|
||||||
|
{
|
||||||
|
User = new[]
|
||||||
|
{
|
||||||
|
new UserFriends
|
||||||
|
{
|
||||||
|
Username = "abc",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var plexAuth = new PlexAuthentication
|
||||||
|
{
|
||||||
|
user = null
|
||||||
|
};
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
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);
|
||||||
|
// When
|
||||||
|
var result = browser.Post("/userlogin", with =>
|
||||||
|
{
|
||||||
|
with.HttpRequest();
|
||||||
|
with.Header("Accept", "application/json");
|
||||||
|
with.FormValue("Username", "abc");
|
||||||
|
with.FormValue("Password", "abc");
|
||||||
|
});
|
||||||
|
|
||||||
|
// Then
|
||||||
|
Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
||||||
|
Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.EqualTo("abc"));
|
||||||
|
|
||||||
|
var body = JsonConvert.DeserializeObject<JsonResponseModel>(result.Body.AsString());
|
||||||
|
Assert.That(body.Result, Is.EqualTo(false));
|
||||||
|
Assert.That(body.Message, Is.Not.Empty);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue