コード例 #1
0
        public async Task AuthRoles_ReaderFailsPut()
        {
            var u = new Bunk.CouchBuiltins.User();

            u.SetPassword("abc");
            u.Name  = Rand.RandString("testuser");
            u.Roles = new List <string>()
            {
                "abc", "def"
            };
            u.GrantReader();

            var resp = await this.db.couchRepo.UserMaintenance().AddUser(u);

            var repo_testuser = CouchRepo.Connect(new ConnectionConfig(Config.Get().Uri.ToString(), u.Name, "abc"));

            var test_doc = new GenericDocument()
            {
                ID = Rand.RandString("test"), TYPE = "dave-test"
            };

            test_doc["test_key"] = "hello";

            resp = await repo_testuser.DB(db.name).Put(test_doc);

            Assert.IsTrue(false, "Should have thrown an forbidden failure for readers");
        }
コード例 #2
0
ファイル: AuthenticationTest.cs プロジェクト: dedels/Bunk
        public async Task Auth_CreateUserAndLoginCookies()
        {
            var adminRepo = CouchRepo.Connect(Config.Get());

            try
            {
                await adminRepo.UserMaintenance().CreateDB();

                Console.WriteLine("Create _users db");
            }
            catch (BunkException ex) { }

            var new_user = new Bunk.CouchBuiltins.User()
            {
                Name = Rand.RandString("auth_test_user"), Roles = new List <string>()
                {
                    "test-role1", "test-role2"
                }
            };

            try {
                new_user.SetPassword("abc");
                new_user.GrantReader().GrantWriter();
                await adminRepo.UserMaintenance().AddUser(new_user);

                //use admin authenticated repo
                var aresp = await adminRepo.Authentication().LoginSession(new_user.Name, "abc");

                Assert.IsNotNull(aresp["AuthSession"]);

                //use unauth endpoint
                var userAuthenticatedRepo = Bunk.CouchRepo.Connect(
                    new TestSessionConfig(Config.Get().Uri, (wr) =>
                {
                    var hwr             = (System.Net.HttpWebRequest)wr;
                    hwr.CookieContainer = new System.Net.CookieContainer();
                    hwr.CookieContainer.Add(aresp);
                    return(wr);
                }));

                var this_user_again = await userAuthenticatedRepo.UserMaintenance().GetUser(new_user.Name);

                Assert.IsNotNull(this_user_again.ID);
            }
            finally
            {
                if (new_user.REV != null)
                {
                    await adminRepo.UserMaintenance().Delete(new_user);
                }
            }
        }