Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding passing test

  • Loading branch information...
commit bd17a76bc5ffd7518871948a789d6e46a6d4d438 1 parent 18e7e68
@ayende ayende authored
View
145 Bundles/Raven.Bundles.Tests/Authentication/Bugs/Mojo2.cs
@@ -0,0 +1,145 @@
+//-----------------------------------------------------------------------
+// <copyright file="Mojo2.cs" company="Hibernating Rhinos LTD">
+// Copyright (c) Hibernating Rhinos LTD. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+extern alias client;
+using System.Collections.Generic;
+using Raven.Bundles.Authorization;
+using Raven.Client;
+using Raven.Client.Document;
+using Raven.Bundles.Tests.Authorization;
+using Xunit;
+
+namespace Raven.Bundles.Tests.Authentication.Bugs
+{
+ public class Mojo2 : AuthorizationTest
+ {
+ private static void SetupRoles(IDocumentSession session)
+ {
+ session.Store(new client::Raven.Bundles.Authorization.Model.AuthorizationRole
+ {
+ Id = "Users"
+ });
+
+ session.Store(new client::Raven.Bundles.Authorization.Model.AuthorizationRole
+ {
+ Id = "Administrators",
+ Permissions =
+ {
+ new client::Raven.Bundles.Authorization.Model.OperationPermission
+ {
+ Allow = true,
+ Operation = "Library/Manage"
+ }
+ }
+ });
+ session.SaveChanges();
+ }
+
+ private static void SetupUsers(IDocumentSession session)
+ {
+ session.Store(new client::Raven.Bundles.Authorization.Model.AuthorizationUser
+ {
+ Id = "andrea",
+ Roles = { "Users", "Administrators" },
+ });
+
+ session.Store(new client::Raven.Bundles.Authorization.Model.AuthorizationUser
+ {
+ Id = "administrator",
+ Roles = { "Users", "Administrators" },
+ });
+
+ //Paolo is a Users with permission for Library/Fake
+ session.Store(new client::Raven.Bundles.Authorization.Model.AuthorizationUser
+ {
+ Id = "paolo",
+ Roles = { "Users" },
+ Permissions =
+ new List<client::Raven.Bundles.Authorization.Model.OperationPermission>
+ {
+ new client::Raven.Bundles.Authorization.Model.OperationPermission
+ {Allow = true, Operation = "Library/Fake"}
+ }
+ });
+
+ session.SaveChanges();
+ }
+
+ [Fact]
+ public void Create_Library_And_Set_Permission_For_Roles_Administrators_And_For_User_Andrea()
+ {
+ using (IDocumentSession session = store.OpenSession())
+ {
+ SetupRoles(session);
+ SetupUsers(session);
+ }
+ using (IDocumentSession session = store.OpenSession())
+ {
+ var library = new Library {Id = "library/andrea-lib"};
+ session.Store(library);
+ client::Raven.Client.Authorization.AuthorizationClientExtensions.SetAuthorizationFor(session, library,
+ new client::Raven.Bundles.
+ Authorization.Model.
+ DocumentAuthorization
+ {
+ Permissions =
+ {
+ new client::Raven.Bundles.
+ Authorization.Model.
+ DocumentPermission
+ {
+ Allow = true,
+ Operation = "Library/View",
+ User = "andrea"
+ },
+ new client::Raven.Bundles.
+ Authorization.Model.
+ DocumentPermission
+ {
+ Allow = true,
+ Operation = "Library/Manage",
+ Role = "Administrators"
+ }
+ }
+ });
+ session.SaveChanges();
+ }
+
+ using (IDocumentSession session = store.OpenSession())
+ {
+ var paolo = session.Load<client::Raven.Bundles.Authorization.Model.AuthorizationUser>("paolo");
+
+ //Paolo is a Users
+ Assert.True(paolo.Roles.Exists(mc => mc.Equals("Users")));
+
+ //Paolo is not an Administrators
+ Assert.True(!paolo.Roles.Exists(mc => mc.Equals("Administrators")));
+
+
+ client::Raven.Bundles.Authorization.OperationAllowedResult paoloCanView =
+ client::Raven.Client.Authorization.AuthorizationClientExtensions.IsOperationAllowedOnDocument(session.Advanced,
+ "paolo",
+ "Library/View",
+ "library/andrea-lib");
+ //Paolo cannot View
+ Assert.True(!paoloCanView.IsAllowed);
+
+
+ client::Raven.Bundles.Authorization.OperationAllowedResult paoloCanMange =
+ client::Raven.Client.Authorization.AuthorizationClientExtensions.IsOperationAllowedOnDocument(session.Advanced,
+ "paolo",
+ "Library/Manage",
+ "library/andrea-lib");
+ //Paolo cannot Manage
+ Assert.True(!paoloCanMange.IsAllowed);
+ }
+ }
+
+ public class Library
+ {
+ public string Id { get; set; }
+ }
+ }
+}
View
1  Bundles/Raven.Bundles.Tests/Raven.Bundles.Tests.csproj
@@ -52,6 +52,7 @@
<ItemGroup>
<Compile Include="Authentication\AuthorizationTest.cs" />
<Compile Include="Authentication\AsyncSimpleLogin.cs" />
+ <Compile Include="Authentication\Bugs\Mojo2.cs" />
<Compile Include="Authentication\HttpWebRequestExtensions.cs" />
<Compile Include="Authentication\SimpleLogin.cs" />
<Compile Include="Authorization\AuthorizationTest.cs" />
Please sign in to comment.
Something went wrong with that request. Please try again.