Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
ISC Open Source Projects
Kea
Commits
8e7af49f
Commit
8e7af49f
authored
Mar 06, 2014
by
Tomek Mrugalski
🛰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[3359] Invalid hostname tests moved from MySQL to shared framework.
parent
ae241216
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
36 deletions
+58
-36
src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc
+2
-36
src/lib/dhcpsrv/tests/test_utils.cc
src/lib/dhcpsrv/tests/test_utils.cc
+44
-0
src/lib/dhcpsrv/tests/test_utils.h
src/lib/dhcpsrv/tests/test_utils.h
+12
-0
No files found.
src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc
View file @
8e7af49f
...
...
@@ -345,24 +345,7 @@ TEST_F(MySqlLeaseMgrTest, lease4NullClientId) {
/// Checks that the it is not possible to create a lease when the hostname
/// length exceeds 255 characters.
TEST_F
(
MySqlLeaseMgrTest
,
lease4InvalidHostname
)
{
// Get the leases to be used for the test.
vector
<
Lease4Ptr
>
leases
=
createLeases4
();
// Create a dummy hostname, consisting of 255 characters.
leases
[
1
]
->
hostname_
.
assign
(
255
,
'a'
);
ASSERT_TRUE
(
lmptr_
->
addLease
(
leases
[
1
]));
// The new lease must be in the database.
Lease4Ptr
l_returned
=
lmptr_
->
getLease4
(
ioaddress4_
[
1
]);
detailCompareLease
(
leases
[
1
],
l_returned
);
// Let's delete the lease, so as we can try to add it again with
// invalid hostname.
EXPECT_TRUE
(
lmptr_
->
deleteLease
(
ioaddress4_
[
1
]));
// Create a hostname with 256 characters. It should not be accepted.
leases
[
1
]
->
hostname_
.
assign
(
256
,
'a'
);
EXPECT_THROW
(
lmptr_
->
addLease
(
leases
[
1
]),
DbOperationError
);
testLease4InvalidHostname
();
}
/// @brief Basic Lease6 Checks
...
...
@@ -378,24 +361,7 @@ TEST_F(MySqlLeaseMgrTest, basicLease6) {
/// Checks that the it is not possible to create a lease when the hostname
/// length exceeds 255 characters.
TEST_F
(
MySqlLeaseMgrTest
,
lease6InvalidHostname
)
{
// Get the leases to be used for the test.
vector
<
Lease6Ptr
>
leases
=
createLeases6
();
// Create a dummy hostname, consisting of 255 characters.
leases
[
1
]
->
hostname_
.
assign
(
255
,
'a'
);
ASSERT_TRUE
(
lmptr_
->
addLease
(
leases
[
1
]));
// The new lease must be in the database.
Lease6Ptr
l_returned
=
lmptr_
->
getLease6
(
leasetype6_
[
1
],
ioaddress6_
[
1
]);
detailCompareLease
(
leases
[
1
],
l_returned
);
// Let's delete the lease, so as we can try to add it again with
// invalid hostname.
EXPECT_TRUE
(
lmptr_
->
deleteLease
(
ioaddress6_
[
1
]));
// Create a hostname with 256 characters. It should not be accepted.
leases
[
1
]
->
hostname_
.
assign
(
256
,
'a'
);
EXPECT_THROW
(
lmptr_
->
addLease
(
leases
[
1
]),
DbOperationError
);
testLease6InvalidHostname
();
}
/// @brief Check GetLease4 methods - access by Hardware Address
...
...
src/lib/dhcpsrv/tests/test_utils.cc
View file @
8e7af49f
...
...
@@ -860,6 +860,50 @@ GenericLeaseMgrTest::testBasicLease6() {
detailCompareLease
(
leases
[
2
],
l_returned
);
}
void
GenericLeaseMgrTest
::
testLease4InvalidHostname
()
{
// Get the leases to be used for the test.
vector
<
Lease4Ptr
>
leases
=
createLeases4
();
// Create a dummy hostname, consisting of 255 characters.
leases
[
1
]
->
hostname_
.
assign
(
255
,
'a'
);
ASSERT_TRUE
(
lmptr_
->
addLease
(
leases
[
1
]));
// The new lease must be in the database.
Lease4Ptr
l_returned
=
lmptr_
->
getLease4
(
ioaddress4_
[
1
]);
detailCompareLease
(
leases
[
1
],
l_returned
);
// Let's delete the lease, so as we can try to add it again with
// invalid hostname.
EXPECT_TRUE
(
lmptr_
->
deleteLease
(
ioaddress4_
[
1
]));
// Create a hostname with 256 characters. It should not be accepted.
leases
[
1
]
->
hostname_
.
assign
(
256
,
'a'
);
EXPECT_THROW
(
lmptr_
->
addLease
(
leases
[
1
]),
DbOperationError
);
}
/// @brief Verify that too long hostname for Lease6 is not accepted.
void
GenericLeaseMgrTest
::
testLease6InvalidHostname
()
{
// Get the leases to be used for the test.
vector
<
Lease6Ptr
>
leases
=
createLeases6
();
// Create a dummy hostname, consisting of 255 characters.
leases
[
1
]
->
hostname_
.
assign
(
255
,
'a'
);
ASSERT_TRUE
(
lmptr_
->
addLease
(
leases
[
1
]));
// The new lease must be in the database.
Lease6Ptr
l_returned
=
lmptr_
->
getLease6
(
leasetype6_
[
1
],
ioaddress6_
[
1
]);
detailCompareLease
(
leases
[
1
],
l_returned
);
// Let's delete the lease, so as we can try to add it again with
// invalid hostname.
EXPECT_TRUE
(
lmptr_
->
deleteLease
(
ioaddress6_
[
1
]));
// Create a hostname with 256 characters. It should not be accepted.
leases
[
1
]
->
hostname_
.
assign
(
256
,
'a'
);
EXPECT_THROW
(
lmptr_
->
addLease
(
leases
[
1
]),
DbOperationError
);
}
};
};
...
...
src/lib/dhcpsrv/tests/test_utils.h
View file @
8e7af49f
...
...
@@ -158,6 +158,18 @@ public:
/// @param check_t1_t2 controls whether T1,T2 timers should be checked
void
testAddGetDelete6
(
bool
check_t1_t2
);
/// @brief Verify that too long hostname for Lease4 is not accepted.
///
/// Checks that the it is not possible to create a lease when the hostname
/// length exceeds 255 characters.
void
testLease4InvalidHostname
();
/// @brief Verify that too long hostname for Lease6 is not accepted.
///
/// Checks that the it is not possible to create a lease when the hostname
/// length exceeds 255 characters.
void
testLease6InvalidHostname
();
// Member variables
std
::
vector
<
std
::
string
>
straddress4_
;
///< String forms of IPv4 addresses
std
::
vector
<
isc
::
asiolink
::
IOAddress
>
ioaddress4_
;
///< IOAddress forms of IPv4 addresses
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment