1 module tests.management.adminRights; 2 3 import tests.management.setup; 4 5 6 /// The revoke admin question should have the right message 7 unittest { 8 auto router = testRouter; 9 collection.empower("user@gmail.com", "admin"); 10 11 auto otherUser = new User("bravo@gmail.com", "other-password"); 12 otherUser.name = "John Bravo"; 13 otherUser.username = "test2"; 14 otherUser.id = 2; 15 collection.add(otherUser); 16 collection.empower("bravo@gmail.com", "admin"); 17 18 router 19 .request 20 .get("/admin/users/2/security/revoke-admin") 21 .header("Cookie", "auth-token=" ~ authToken.name) 22 .end((Response response) => { 23 response.bodyString.should.contain("Revoke admin"); 24 response.bodyString.should.contain("Are you sure you want to revoke the admin rights of this user?"); 25 response.bodyString.should.contain("Revoke"); 26 response.bodyString.should.contain("/2/security/revoke-admin"); 27 }); 28 } 29 30 /// The revoke admin action should remove the admin rights 31 unittest { 32 auto router = testRouter; 33 collection.empower("user@gmail.com", "admin"); 34 35 auto otherUser = new User("bravo@gmail.com", "other-password"); 36 otherUser.name = "John Bravo"; 37 otherUser.username = "test2"; 38 otherUser.id = 2; 39 collection.add(otherUser); 40 collection.empower("bravo@gmail.com", "admin"); 41 42 router 43 .request 44 .post("/admin/users/2/security/revoke-admin") 45 .header("Cookie", "auth-token=" ~ authToken.name) 46 .send(["password": "password"]) 47 .expectStatusCode(302) 48 .expectHeader("Location", "http://localhost:0/admin/users/2/security") 49 .end((Response response) => { 50 collection.byId("2").getScopes().should.not.contain("admin"); 51 }); 52 } 53 54 /// The make admin question should have the right message 55 unittest { 56 auto router = testRouter; 57 collection.empower("user@gmail.com", "admin"); 58 59 auto otherUser = new User("bravo@gmail.com", "other-password"); 60 otherUser.name = "John Bravo"; 61 otherUser.username = "test2"; 62 otherUser.id = 2; 63 collection.add(otherUser); 64 65 router 66 .request 67 .get("/admin/users/2/security/make-admin") 68 .header("Cookie", "auth-token=" ~ authToken.name) 69 .end((Response response) => { 70 response.bodyString.should.contain("Make admin"); 71 response.bodyString.should.contain("Are you sure you want to add admin rights to this user?"); 72 response.bodyString.should.contain("Make"); 73 response.bodyString.should.contain("/2/security/make-admin"); 74 }); 75 } 76 77 /// The make admin action should add the admin rights 78 unittest { 79 auto router = testRouter; 80 collection.empower("user@gmail.com", "admin"); 81 82 auto otherUser = new User("bravo@gmail.com", "other-password"); 83 otherUser.name = "John Bravo"; 84 otherUser.username = "test2"; 85 otherUser.id = 2; 86 collection.add(otherUser); 87 88 router 89 .request 90 .post("/admin/users/2/security/make-admin") 91 .header("Cookie", "auth-token=" ~ authToken.name) 92 .send(["password": "password"]) 93 .expectStatusCode(302) 94 .expectHeader("Location", "http://localhost:0/admin/users/2/security") 95 .end((Response response) => { 96 collection.byId("2").getScopes().should.contain("admin"); 97 }); 98 } 99 100 /// The make admin action should not add the admin rights if the password is invalid 101 unittest { 102 auto router = testRouter; 103 collection.empower("user@gmail.com", "admin"); 104 105 auto otherUser = new User("bravo@gmail.com", "other-password"); 106 otherUser.name = "John Bravo"; 107 otherUser.username = "test2"; 108 otherUser.id = 2; 109 collection.add(otherUser); 110 111 router 112 .request 113 .post("/admin/users/2/security/make-admin") 114 .header("Cookie", "auth-token=" ~ authToken.name) 115 .send(["password": "other-password"]) 116 .expectStatusCode(302) 117 .expectHeader("Location", "http://localhost:0/admin/users/2/security?error=Can%20not%20make%20admin.%20The%20password%20was%20invalid.") 118 .end((Response response) => { 119 collection.byId("2").getScopes().should.not.contain("admin"); 120 }); 121 }