diff options
author | crupest <crupest@outlook.com> | 2022-04-11 19:44:32 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-04-11 19:44:32 +0800 |
commit | f43fb6ea362e52ba5ef07c9ff405b4a17532dab1 (patch) | |
tree | 1feb5b47f192bf53a9ab6c97ed51cc47c12276e1 /BackEnd/Timeline.Tests/IntegratedTests2/TimelineBookmarkTest2.cs | |
parent | 88339df298016496d814e4df7d3abdf26e84447c (diff) | |
download | timeline-f43fb6ea362e52ba5ef07c9ff405b4a17532dab1.tar.gz timeline-f43fb6ea362e52ba5ef07c9ff405b4a17532dab1.tar.bz2 timeline-f43fb6ea362e52ba5ef07c9ff405b4a17532dab1.zip |
...
Diffstat (limited to 'BackEnd/Timeline.Tests/IntegratedTests2/TimelineBookmarkTest2.cs')
-rw-r--r-- | BackEnd/Timeline.Tests/IntegratedTests2/TimelineBookmarkTest2.cs | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/BackEnd/Timeline.Tests/IntegratedTests2/TimelineBookmarkTest2.cs b/BackEnd/Timeline.Tests/IntegratedTests2/TimelineBookmarkTest2.cs index 6bc93836..95c1dd97 100644 --- a/BackEnd/Timeline.Tests/IntegratedTests2/TimelineBookmarkTest2.cs +++ b/BackEnd/Timeline.Tests/IntegratedTests2/TimelineBookmarkTest2.cs @@ -31,6 +31,12 @@ namespace Timeline.Tests.IntegratedTests2 }, expectedStatusCode: HttpStatusCode.Created); } + private async Task ChangeVisibilityAsync(TimelineVisibility visibility) + { + using var client = CreateClientAsUser(); + await client.TestJsonSendAsync(HttpMethod.Put, "v2/users/user/bookmarks/visibility", new HttpTimelineBookmarkVisibility { Visibility = visibility }, expectedStatusCode: HttpStatusCode.NoContent); + } + [Fact] public async Task ChangeVisibilityShouldWork() { @@ -46,6 +52,87 @@ namespace Timeline.Tests.IntegratedTests2 var c = await client.TestJsonSendAsync<HttpTimelineBookmarkVisibility>(HttpMethod.Get, "v2/users/user/bookmarks/visibility", expectedStatusCode: HttpStatusCode.OK); c.Visibility.Should().Be(TimelineVisibility.Public); } + + [Fact] + public async Task AnonymousCantSeePrivate() + { + using var client = CreateDefaultClient(); + await client.TestJsonSendAsync(HttpMethod.Get, "v2/users/user/bookmarks", expectedStatusCode: HttpStatusCode.Forbidden); + await client.TestJsonSendAsync(HttpMethod.Get, "v2/users/user/bookmarks/1", expectedStatusCode: HttpStatusCode.Forbidden); + } + + [Fact] + public async Task OtherUserCantSeePrivate() + { + await CreateUserAsync("user2", "user2pw"); + var client = CreateClientWithToken(await CreateTokenWithCredentialAsync("user2", "user2pw")); + await client.TestJsonSendAsync(HttpMethod.Get, "v2/users/user/bookmarks", expectedStatusCode: HttpStatusCode.Forbidden); + await client.TestJsonSendAsync(HttpMethod.Get, "v2/users/user/bookmarks/1", expectedStatusCode: HttpStatusCode.Forbidden); + } + + [Fact] + public async Task AdminCanSeePrivate() + { + using var client = CreateClientAsAdmin(); + await client.TestJsonSendAsync(HttpMethod.Get, "v2/users/user/bookmarks", expectedStatusCode: HttpStatusCode.OK); + await client.TestJsonSendAsync(HttpMethod.Get, "v2/users/user/bookmarks/1", expectedStatusCode: HttpStatusCode.OK); + } + + [Fact] + public async Task AnonymousCantSeeRegister() + { + await ChangeVisibilityAsync(TimelineVisibility.Register); + using var client = CreateDefaultClient(); + await client.TestJsonSendAsync(HttpMethod.Get, "v2/users/user/bookmarks", expectedStatusCode: HttpStatusCode.Forbidden); + await client.TestJsonSendAsync(HttpMethod.Get, "v2/users/user/bookmarks/1", expectedStatusCode: HttpStatusCode.Forbidden); + } + + [Fact] + public async Task OtherUserCanSeeRegister() + { + await ChangeVisibilityAsync(TimelineVisibility.Register); + await CreateUserAsync("user2", "user2pw"); + var client = CreateClientWithToken(await CreateTokenWithCredentialAsync("user2", "user2pw")); + await client.TestJsonSendAsync(HttpMethod.Get, "v2/users/user/bookmarks", expectedStatusCode: HttpStatusCode.OK); + await client.TestJsonSendAsync(HttpMethod.Get, "v2/users/user/bookmarks/1", expectedStatusCode: HttpStatusCode.OK); + } + + [Fact] + public async Task AdminCanSeeRegister() + { + await ChangeVisibilityAsync(TimelineVisibility.Register); + using var client = CreateClientAsAdmin(); + await client.TestJsonSendAsync(HttpMethod.Get, "v2/users/user/bookmarks", expectedStatusCode: HttpStatusCode.OK); + await client.TestJsonSendAsync(HttpMethod.Get, "v2/users/user/bookmarks/1", expectedStatusCode: HttpStatusCode.OK); + } + + [Fact] + public async Task AnonymousCanSeePublic() + { + await ChangeVisibilityAsync(TimelineVisibility.Public); + using var client = CreateDefaultClient(); + await client.TestJsonSendAsync(HttpMethod.Get, "v2/users/user/bookmarks", expectedStatusCode: HttpStatusCode.OK); + await client.TestJsonSendAsync(HttpMethod.Get, "v2/users/user/bookmarks/1", expectedStatusCode: HttpStatusCode.OK); + } + + [Fact] + public async Task OtherUserCanSeePublic() + { + await ChangeVisibilityAsync(TimelineVisibility.Public); + await CreateUserAsync("user2", "user2pw"); + var client = CreateClientWithToken(await CreateTokenWithCredentialAsync("user2", "user2pw")); + await client.TestJsonSendAsync(HttpMethod.Get, "v2/users/user/bookmarks", expectedStatusCode: HttpStatusCode.OK); + await client.TestJsonSendAsync(HttpMethod.Get, "v2/users/user/bookmarks/1", expectedStatusCode: HttpStatusCode.OK); + } + + [Fact] + public async Task AdminCanSeePublic() + { + await ChangeVisibilityAsync(TimelineVisibility.Public); + using var client = CreateClientAsAdmin(); + await client.TestJsonSendAsync(HttpMethod.Get, "v2/users/user/bookmarks", expectedStatusCode: HttpStatusCode.OK); + await client.TestJsonSendAsync(HttpMethod.Get, "v2/users/user/bookmarks/1", expectedStatusCode: HttpStatusCode.OK); + } } } |