broker/AuthorizationsCollectorTest: code formatter used
This commit is contained in:
+21
-19
@@ -13,13 +13,12 @@
|
|||||||
*
|
*
|
||||||
* You may elect to redistribute this code under either of these licenses.
|
* You may elect to redistribute this code under either of these licenses.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.moquette.spi.impl.security;
|
package io.moquette.spi.impl.security;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -28,8 +27,12 @@ import static org.junit.Assert.*;
|
|||||||
public class AuthorizationsCollectorTest {
|
public class AuthorizationsCollectorTest {
|
||||||
|
|
||||||
private static final Authorization RW_ANEMOMETER = new Authorization("/weather/italy/anemometer");
|
private static final Authorization RW_ANEMOMETER = new Authorization("/weather/italy/anemometer");
|
||||||
private static final Authorization R_ANEMOMETER = new Authorization("/weather/italy/anemometer", Authorization.Permission.READ);
|
private static final Authorization R_ANEMOMETER = new Authorization(
|
||||||
private static final Authorization W_ANEMOMETER = new Authorization("/weather/italy/anemometer", Authorization.Permission.WRITE);
|
"/weather/italy/anemometer",
|
||||||
|
Authorization.Permission.READ);
|
||||||
|
private static final Authorization W_ANEMOMETER = new Authorization(
|
||||||
|
"/weather/italy/anemometer",
|
||||||
|
Authorization.Permission.WRITE);
|
||||||
|
|
||||||
private AuthorizationsCollector authorizator;
|
private AuthorizationsCollector authorizator;
|
||||||
|
|
||||||
@@ -42,7 +45,7 @@ public class AuthorizationsCollectorTest {
|
|||||||
public void testParseAuthLineValid() throws ParseException {
|
public void testParseAuthLineValid() throws ParseException {
|
||||||
Authorization authorization = authorizator.parseAuthLine("topic /weather/italy/anemometer");
|
Authorization authorization = authorizator.parseAuthLine("topic /weather/italy/anemometer");
|
||||||
|
|
||||||
//Verify
|
// Verify
|
||||||
assertEquals(RW_ANEMOMETER, authorization);
|
assertEquals(RW_ANEMOMETER, authorization);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +53,7 @@ public class AuthorizationsCollectorTest {
|
|||||||
public void testParseAuthLineValid_read() throws ParseException {
|
public void testParseAuthLineValid_read() throws ParseException {
|
||||||
Authorization authorization = authorizator.parseAuthLine("topic read /weather/italy/anemometer");
|
Authorization authorization = authorizator.parseAuthLine("topic read /weather/italy/anemometer");
|
||||||
|
|
||||||
//Verify
|
// Verify
|
||||||
assertEquals(R_ANEMOMETER, authorization);
|
assertEquals(R_ANEMOMETER, authorization);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,7 +61,7 @@ public class AuthorizationsCollectorTest {
|
|||||||
public void testParseAuthLineValid_write() throws ParseException {
|
public void testParseAuthLineValid_write() throws ParseException {
|
||||||
Authorization authorization = authorizator.parseAuthLine("topic write /weather/italy/anemometer");
|
Authorization authorization = authorizator.parseAuthLine("topic write /weather/italy/anemometer");
|
||||||
|
|
||||||
//Verify
|
// Verify
|
||||||
assertEquals(W_ANEMOMETER, authorization);
|
assertEquals(W_ANEMOMETER, authorization);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,17 +69,16 @@ public class AuthorizationsCollectorTest {
|
|||||||
public void testParseAuthLineValid_readwrite() throws ParseException {
|
public void testParseAuthLineValid_readwrite() throws ParseException {
|
||||||
Authorization authorization = authorizator.parseAuthLine("topic readwrite /weather/italy/anemometer");
|
Authorization authorization = authorizator.parseAuthLine("topic readwrite /weather/italy/anemometer");
|
||||||
|
|
||||||
//Verify
|
// Verify
|
||||||
assertEquals(RW_ANEMOMETER, authorization);
|
assertEquals(RW_ANEMOMETER, authorization);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseAuthLineValid_topic_with_space() throws ParseException {
|
public void testParseAuthLineValid_topic_with_space() throws ParseException {
|
||||||
Authorization expected = new Authorization("/weather/eastern italy/anemometer");
|
Authorization expected = new Authorization("/weather/eastern italy/anemometer");
|
||||||
Authorization authorization = authorizator.parseAuthLine("topic readwrite /weather/eastern italy/anemometer");
|
Authorization authorization = authorizator.parseAuthLine("topic readwrite /weather/eastern italy/anemometer");
|
||||||
|
|
||||||
//Verify
|
// Verify
|
||||||
assertEquals(expected, authorization);
|
assertEquals(expected, authorization);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +91,7 @@ public class AuthorizationsCollectorTest {
|
|||||||
public void testCanWriteSimpleTopic() throws ParseException {
|
public void testCanWriteSimpleTopic() throws ParseException {
|
||||||
authorizator.parse("topic write /sensors");
|
authorizator.parse("topic write /sensors");
|
||||||
|
|
||||||
//verify
|
// verify
|
||||||
assertTrue(authorizator.canWrite("/sensors", "", ""));
|
assertTrue(authorizator.canWrite("/sensors", "", ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +99,7 @@ public class AuthorizationsCollectorTest {
|
|||||||
public void testCanReadSimpleTopic() throws ParseException {
|
public void testCanReadSimpleTopic() throws ParseException {
|
||||||
authorizator.parse("topic read /sensors");
|
authorizator.parse("topic read /sensors");
|
||||||
|
|
||||||
//verify
|
// verify
|
||||||
assertTrue(authorizator.canRead("/sensors", "", ""));
|
assertTrue(authorizator.canRead("/sensors", "", ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,7 +108,7 @@ public class AuthorizationsCollectorTest {
|
|||||||
authorizator.parse("topic write /sensors");
|
authorizator.parse("topic write /sensors");
|
||||||
authorizator.parse("topic read /sensors/anemometer");
|
authorizator.parse("topic read /sensors/anemometer");
|
||||||
|
|
||||||
//verify
|
// verify
|
||||||
assertTrue(authorizator.canWrite("/sensors", "", ""));
|
assertTrue(authorizator.canWrite("/sensors", "", ""));
|
||||||
assertFalse(authorizator.canRead("/sensors", "", ""));
|
assertFalse(authorizator.canRead("/sensors", "", ""));
|
||||||
}
|
}
|
||||||
@@ -115,7 +117,7 @@ public class AuthorizationsCollectorTest {
|
|||||||
public void testCanWriteMultiMatherTopic() throws ParseException {
|
public void testCanWriteMultiMatherTopic() throws ParseException {
|
||||||
authorizator.parse("topic write /sensors/#");
|
authorizator.parse("topic write /sensors/#");
|
||||||
|
|
||||||
//verify
|
// verify
|
||||||
assertTrue(authorizator.canWrite("/sensors/anemometer/wind", "", ""));
|
assertTrue(authorizator.canWrite("/sensors/anemometer/wind", "", ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,7 +125,7 @@ public class AuthorizationsCollectorTest {
|
|||||||
public void testCanWriteSingleMatherTopic() throws ParseException {
|
public void testCanWriteSingleMatherTopic() throws ParseException {
|
||||||
authorizator.parse("topic write /sensors/+");
|
authorizator.parse("topic write /sensors/+");
|
||||||
|
|
||||||
//verify
|
// verify
|
||||||
assertTrue(authorizator.canWrite("/sensors/anemometer", "", ""));
|
assertTrue(authorizator.canWrite("/sensors/anemometer", "", ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,7 +134,7 @@ public class AuthorizationsCollectorTest {
|
|||||||
authorizator.parse("user john");
|
authorizator.parse("user john");
|
||||||
authorizator.parse("topic write /sensors");
|
authorizator.parse("topic write /sensors");
|
||||||
|
|
||||||
//verify
|
// verify
|
||||||
assertTrue(authorizator.canWrite("/sensors", "john", ""));
|
assertTrue(authorizator.canWrite("/sensors", "john", ""));
|
||||||
assertFalse(authorizator.canWrite("/sensors", "jack", ""));
|
assertFalse(authorizator.canWrite("/sensors", "jack", ""));
|
||||||
}
|
}
|
||||||
@@ -141,7 +143,7 @@ public class AuthorizationsCollectorTest {
|
|||||||
public void testPatternClientLineACL() throws ParseException {
|
public void testPatternClientLineACL() throws ParseException {
|
||||||
authorizator.parse("pattern read /weather/italy/%c");
|
authorizator.parse("pattern read /weather/italy/%c");
|
||||||
|
|
||||||
//Verify
|
// Verify
|
||||||
assertTrue(authorizator.canRead("/weather/italy/anemometer1", "", "anemometer1"));
|
assertTrue(authorizator.canRead("/weather/italy/anemometer1", "", "anemometer1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,7 +151,7 @@ public class AuthorizationsCollectorTest {
|
|||||||
public void testPatternClientAndUserLineACL() throws ParseException {
|
public void testPatternClientAndUserLineACL() throws ParseException {
|
||||||
authorizator.parse("pattern read /weather/%u/%c");
|
authorizator.parse("pattern read /weather/%u/%c");
|
||||||
|
|
||||||
//Verify
|
// Verify
|
||||||
assertTrue(authorizator.canRead("/weather/italy/anemometer1", "italy", "anemometer1"));
|
assertTrue(authorizator.canRead("/weather/italy/anemometer1", "italy", "anemometer1"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user