Implemented the part of parsing and accessing the user specific ACLs
This commit is contained in:
-1
@@ -29,7 +29,6 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ public class ProtocolProcessorTest {
|
||||
throw new AssertionError("Wrong return code");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This a synchronous channel that avoid output ring buffer from Processor
|
||||
@@ -141,7 +141,7 @@ public class ProtocolProcessorTest {
|
||||
throw new AssertionError("Wrong return code");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws InterruptedException {
|
||||
|
||||
@@ -20,8 +20,6 @@ import org.junit.Test;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.text.ParseException;
|
||||
import java.util.List;
|
||||
import static org.eclipse.moquette.spi.impl.security.Authorization.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@@ -60,8 +58,8 @@ public class ACLFileParserTest {
|
||||
AuthorizationsCollector authorizations = ACLFileParser.parse(conf);
|
||||
|
||||
//Verify
|
||||
assertTrue(authorizations.canRead("/weather/italy/anemometer"));
|
||||
assertTrue(authorizations.canWrite("/weather/italy/anemometer"));
|
||||
assertTrue(authorizations.canRead("/weather/italy/anemometer", ""));
|
||||
assertTrue(authorizations.canWrite("/weather/italy/anemometer", ""));
|
||||
}
|
||||
|
||||
}
|
||||
+22
-13
@@ -20,7 +20,6 @@ import org.junit.Test;
|
||||
|
||||
import java.text.ParseException;
|
||||
|
||||
import static org.eclipse.moquette.spi.impl.security.AuthorizationsCollector.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
@@ -41,7 +40,7 @@ public class AuthorizationsCollectorTest {
|
||||
|
||||
@Test
|
||||
public void testParseAuthLineValid() throws ParseException {
|
||||
Authorization authorization = parseAuthLine("topic /weather/italy/anemometer");
|
||||
Authorization authorization = authorizator.parseAuthLine("topic /weather/italy/anemometer");
|
||||
|
||||
//Verify
|
||||
assertEquals(RW_ANEMOMETER, authorization);
|
||||
@@ -49,7 +48,7 @@ public class AuthorizationsCollectorTest {
|
||||
|
||||
@Test
|
||||
public void testParseAuthLineValid_read() throws ParseException {
|
||||
Authorization authorization = parseAuthLine("topic read /weather/italy/anemometer");
|
||||
Authorization authorization = authorizator.parseAuthLine("topic read /weather/italy/anemometer");
|
||||
|
||||
//Verify
|
||||
assertEquals(R_ANEMOMETER, authorization);
|
||||
@@ -57,7 +56,7 @@ public class AuthorizationsCollectorTest {
|
||||
|
||||
@Test
|
||||
public void testParseAuthLineValid_write() throws ParseException {
|
||||
Authorization authorization = parseAuthLine("topic write /weather/italy/anemometer");
|
||||
Authorization authorization = authorizator.parseAuthLine("topic write /weather/italy/anemometer");
|
||||
|
||||
//Verify
|
||||
assertEquals(W_ANEMOMETER, authorization);
|
||||
@@ -65,7 +64,7 @@ public class AuthorizationsCollectorTest {
|
||||
|
||||
@Test
|
||||
public void testParseAuthLineValid_readwrite() throws ParseException {
|
||||
Authorization authorization = parseAuthLine("topic readwrite /weather/italy/anemometer");
|
||||
Authorization authorization = authorizator.parseAuthLine("topic readwrite /weather/italy/anemometer");
|
||||
|
||||
//Verify
|
||||
assertEquals(RW_ANEMOMETER, authorization);
|
||||
@@ -75,7 +74,7 @@ public class AuthorizationsCollectorTest {
|
||||
@Test
|
||||
public void testParseAuthLineValid_topic_with_space() throws ParseException {
|
||||
Authorization expected = new Authorization("/weather/eastern italy/anemometer");
|
||||
Authorization authorization = parseAuthLine("topic readwrite /weather/eastern italy/anemometer");
|
||||
Authorization authorization = authorizator.parseAuthLine("topic readwrite /weather/eastern italy/anemometer");
|
||||
|
||||
//Verify
|
||||
assertEquals(expected, authorization);
|
||||
@@ -83,7 +82,7 @@ public class AuthorizationsCollectorTest {
|
||||
|
||||
@Test(expected = ParseException.class)
|
||||
public void testParseAuthLineValid_invalid() throws ParseException {
|
||||
parseAuthLine("topic faker /weather/italy/anemometer");
|
||||
authorizator.parseAuthLine("topic faker /weather/italy/anemometer");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -91,7 +90,7 @@ public class AuthorizationsCollectorTest {
|
||||
authorizator.parse("topic write /sensors");
|
||||
|
||||
//verify
|
||||
assertTrue(authorizator.canWrite("/sensors"));
|
||||
assertTrue(authorizator.canWrite("/sensors", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -99,7 +98,7 @@ public class AuthorizationsCollectorTest {
|
||||
authorizator.parse("topic read /sensors");
|
||||
|
||||
//verify
|
||||
assertTrue(authorizator.canRead("/sensors"));
|
||||
assertTrue(authorizator.canRead("/sensors", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -108,8 +107,8 @@ public class AuthorizationsCollectorTest {
|
||||
authorizator.parse("topic read /sensors/anemometer");
|
||||
|
||||
//verify
|
||||
assertTrue(authorizator.canWrite("/sensors"));
|
||||
assertFalse(authorizator.canRead("/sensors"));
|
||||
assertTrue(authorizator.canWrite("/sensors", ""));
|
||||
assertFalse(authorizator.canRead("/sensors", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -117,7 +116,7 @@ public class AuthorizationsCollectorTest {
|
||||
authorizator.parse("topic write /sensors/#");
|
||||
|
||||
//verify
|
||||
assertTrue(authorizator.canWrite("/sensors/anemometer/wind"));
|
||||
assertTrue(authorizator.canWrite("/sensors/anemometer/wind", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -125,6 +124,16 @@ public class AuthorizationsCollectorTest {
|
||||
authorizator.parse("topic write /sensors/+");
|
||||
|
||||
//verify
|
||||
assertTrue(authorizator.canWrite("/sensors/anemometer"));
|
||||
assertTrue(authorizator.canWrite("/sensors/anemometer", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCanWriteUserTopic() throws ParseException {
|
||||
authorizator.parse("user john");
|
||||
authorizator.parse("topic write /sensors");
|
||||
|
||||
//verify
|
||||
assertTrue(authorizator.canWrite("/sensors", "john"));
|
||||
assertFalse(authorizator.canWrite("/sensors", "jack"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user