1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.shiro.web.filter.authz;
20
21 import junit.framework.Assert;
22 import org.junit.Test;
23
24
25 public class HttpMethodPermissionFilterTest {
26
27 @Test
28 public void testPermisisonMapping() {
29
30
31 HttpMethodPermissionFilter filter = new HttpMethodPermissionFilter();
32
33 String[] permsBefore = {"foo", "bar"};
34
35 String[] permsAfter = filter.buildPermissions(permsBefore, filter.getHttpMethodAction("get"));
36 Assert.assertEquals(2, permsAfter.length);
37 Assert.assertEquals("foo:read", permsAfter[0]);
38 Assert.assertEquals("bar:read", permsAfter[1]);
39
40 Assert.assertEquals("foo:read", filter.buildPermissions(permsBefore, filter.getHttpMethodAction("head"))[0]);
41 Assert.assertEquals("foo:update", filter.buildPermissions(permsBefore, filter.getHttpMethodAction("put"))[0]);
42 Assert.assertEquals("foo:create", filter.buildPermissions(permsBefore, filter.getHttpMethodAction("post"))[0]);
43 Assert.assertEquals("foo:create", filter.buildPermissions(permsBefore, filter.getHttpMethodAction("mkcol"))[0]);
44 Assert.assertEquals("foo:delete", filter.buildPermissions(permsBefore, filter.getHttpMethodAction("delete"))[0]);
45 Assert.assertEquals("foo:read", filter.buildPermissions(permsBefore, filter.getHttpMethodAction("options"))[0]);
46 Assert.assertEquals("foo:read", filter.buildPermissions(permsBefore, filter.getHttpMethodAction("trace"))[0]);
47 }
48 }