Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
briar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julian Dehm
briar
Commits
24f733ed
Unverified
Commit
24f733ed
authored
9 years ago
by
Santiago Torres-Arias
Browse files
Options
Downloads
Patches
Plain Diff
WIP: Adds Transport properly validator test
parent
e458853f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
briar-tests/src/org/briarproject/TestUtils.java
+6
-0
6 additions, 0 deletions
briar-tests/src/org/briarproject/TestUtils.java
briar-tests/src/org/briarproject/properties/TransportPropertyValidatorTest.java
+141
-3
141 additions, 3 deletions
...iarproject/properties/TransportPropertyValidatorTest.java
with
147 additions
and
3 deletions
briar-tests/src/org/briarproject/TestUtils.java
+
6
−
0
View file @
24f733ed
...
...
@@ -32,6 +32,12 @@ public class TestUtils {
return
b
;
}
public
static
byte
[]
getRandomBytes
(
int
length
)
{
byte
[]
b
=
new
byte
[
length
];
random
.
nextBytes
(
b
);
return
b
;
}
public
static
String
createRandomString
(
int
length
)
{
char
[]
c
=
new
char
[
length
];
for
(
int
i
=
0
;
i
<
length
;
i
++)
...
...
This diff is collapsed.
Click to expand it.
briar-tests/src/org/briarproject/properties/TransportPropertyValidatorTest.java
+
141
−
3
View file @
24f733ed
...
...
@@ -4,11 +4,149 @@ import org.briarproject.BriarTestCase;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
fail
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
org.briarproject.api.data.BdfWriter
;
import
java.io.ByteArrayInputStream
;
import
java.io.IOException
;
import
java.util.HashMap
;
import
org.briarproject.properties.TransportPropertyValidator
;
import
org.briarproject.api.properties.TransportProperties
;
import
org.briarproject.api.TransportId
;
import
org.briarproject.api.sync.MessageId
;
import
org.briarproject.api.UniqueId
;
import
org.briarproject.api.sync.GroupId
;
import
org.briarproject.api.sync.ClientId
;
import
org.briarproject.api.DeviceId
;
import
org.briarproject.api.data.BdfWriter
;
import
org.briarproject.api.data.BdfList
;
import
org.briarproject.api.data.BdfReader
;
import
org.briarproject.api.clients.ClientHelper
;
import
org.briarproject.api.data.BdfDictionary
;
import
org.briarproject.api.data.BdfEntry
;
import
org.briarproject.api.data.MetadataEncoder
;
import
org.briarproject.api.system.Clock
;
import
org.briarproject.api.DeviceId
;
import
org.briarproject.api.FormatException
;
import
org.briarproject.api.sync.Group
;
import
org.briarproject.api.sync.Message
;
import
org.briarproject.api.properties.TransportPropertyManager
;
import
org.briarproject.TestUtils
;
import
org.briarproject.util.StringUtils
;
import
static
org
.
briarproject
.
api
.
TransportId
.
MAX_TRANSPORT_ID_LENGTH
;
import
static
org
.
briarproject
.
api
.
properties
.
TransportPropertyConstants
.
MAX_PROPERTIES_PER_TRANSPORT
;
import
org.jmock.Expectations
;
import
org.jmock.Mockery
;
public
class
TransportPropertyValidatorTest
extends
BriarTestCase
{
@Test
public
void
testUnitTestsExist
()
{
fail
();
// FIXME: Write tests
private
TransportId
transportId
;
private
MessageId
messageId
;
private
GroupId
groupId
;
private
ClientId
clientId
;
private
DeviceId
deviceId
;
private
final
ClientHelper
h
;
private
final
MetadataEncoder
e
;
private
final
Clock
c
;
private
final
Group
g
;
private
final
TransportPropertyValidator
tpv
;
private
final
BdfDictionary
d
;
public
TransportPropertyValidatorTest
()
{
transportId
=
new
TransportId
(
"test"
);
messageId
=
new
MessageId
(
TestUtils
.
getRandomId
());
groupId
=
new
GroupId
(
TestUtils
.
getRandomId
());
clientId
=
new
ClientId
(
TestUtils
.
getRandomId
());
deviceId
=
new
DeviceId
(
TestUtils
.
getRandomId
());
Mockery
context
=
new
Mockery
();
h
=
context
.
mock
(
ClientHelper
.
class
);
e
=
context
.
mock
(
MetadataEncoder
.
class
);
c
=
context
.
mock
(
Clock
.
class
);
g
=
new
Group
(
groupId
,
clientId
,
TestUtils
.
getRandomBytes
(
12
));
d
=
new
BdfDictionary
();
tpv
=
new
TransportPropertyValidator
(
h
,
e
,
c
);
}
@Test
public
void
testValidateProperMessage
()
throws
IOException
{
BdfDictionary
result
;
final
BdfList
m
=
BdfList
.
of
(
deviceId
,
transportId
.
getString
(),
4
,
d
);
result
=
tpv
.
validateMessage
(
m
,
g
,
1L
);
assertEquals
(
"test"
,
result
.
getString
(
"transportId"
));
assertEquals
(
result
.
getLong
(
"version"
).
longValue
(),
4
);
}
@Test
(
expected
=
FormatException
.
class
)
public
void
testValidateWrongVersionValue
()
throws
IOException
{
/* Will create a negative version number */
BdfList
m
=
BdfList
.
of
(
deviceId
,
transportId
.
getString
(),
-
1
,
d
);
tpv
.
validateMessage
(
m
,
g
,
1L
);
}
@Test
(
expected
=
FormatException
.
class
)
public
void
testValidateWrongVersionType
()
throws
IOException
{
/* Instead of sending a version number I'm sending a dict */
BdfList
m
=
BdfList
.
of
(
deviceId
,
transportId
.
getString
(),
d
,
d
);
tpv
.
validateMessage
(
m
,
g
,
1L
);
}
@Test
(
expected
=
FormatException
.
class
)
public
void
testValidateShortDeviceId
()
throws
IOException
{
/* Will create a Device Id with a short length, getRaw should work */
BdfList
m
=
BdfList
.
of
(
new
byte
[
UniqueId
.
LENGTH
-
1
],
transportId
.
getString
(),
1
,
d
);
tpv
.
validateMessage
(
m
,
g
,
1L
);
}
@Test
(
expected
=
FormatException
.
class
)
public
void
testValidateLongDeviceId
()
throws
IOException
{
BdfList
m
=
BdfList
.
of
(
new
byte
[
UniqueId
.
LENGTH
+
1
],
transportId
.
getString
(),
1
,
d
);
tpv
.
validateMessage
(
m
,
g
,
1L
);
}
@Test
(
expected
=
FormatException
.
class
)
public
void
testValidateWrongDeviceId
()
throws
IOException
{
BdfList
m
=
BdfList
.
of
(
d
,
transportId
.
getString
(),
1
,
d
);
tpv
.
validateMessage
(
m
,
g
,
1L
);
}
@Test
(
expected
=
FormatException
.
class
)
public
void
testValidateLongTransportId
()
throws
IOException
{
/* Generate a string or arbitrary length for the transport id*/
String
wrongTransportIdString
=
TestUtils
.
createRandomString
(
MAX_TRANSPORT_ID_LENGTH
+
1
);
BdfList
m
=
BdfList
.
of
(
deviceId
,
wrongTransportIdString
,
4
,
d
);
tpv
.
validateMessage
(
m
,
g
,
1L
);
}
@Test
(
expected
=
FormatException
.
class
)
public
void
testValidateTooManyProperties
()
throws
IOException
{
/* Generate a big map for the BdfDictionary*/
HashMap
map
=
new
HashMap
();
for
(
int
i
=
0
;
i
<
MAX_PROPERTIES_PER_TRANSPORT
+
1
;
i
++)
map
.
put
(
""
+
i
,
""
+
i
);
BdfDictionary
d
=
new
BdfDictionary
(
map
);
BdfList
m
=
BdfList
.
of
(
deviceId
,
transportId
.
getString
(),
4
,
d
);
tpv
.
validateMessage
(
m
,
g
,
1L
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment