summaryrefslogtreecommitdiffstats
path: root/base/guid_unittest.cc
diff options
context:
space:
mode:
authorbenchan <benchan@chromium.org>2014-09-05 07:19:39 -0700
committerCommit bot <commit-bot@chromium.org>2014-09-05 14:31:31 +0000
commit87119864277bb405bf1303d98691f5acd5add403 (patch)
treeba7b121fb0deb9a80bfde4d44d17216921c73cef /base/guid_unittest.cc
parentd6f2fa209bab91490944004b5189cd4191e09024 (diff)
downloadchromium_src-87119864277bb405bf1303d98691f5acd5add403.zip
chromium_src-87119864277bb405bf1303d98691f5acd5add403.tar.gz
chromium_src-87119864277bb405bf1303d98691f5acd5add403.tar.bz2
Make GUID generation on POSIX compliant with GUID v4 format.
Per RFC 4122 section 4.4, the format of GUID version 4 must be xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx, where y is one of [8, 9, A, B]. This CL updates base::GenerateGUID() on POSIX to be compliant with the GUID v4 format. This fix is proposed by Alex Vakulenko <avakulenko@chromium.org> BUG=None TEST=base_unittests Review URL: https://codereview.chromium.org/541633005 Cr-Commit-Position: refs/heads/master@{#293518}
Diffstat (limited to 'base/guid_unittest.cc')
-rw-r--r--base/guid_unittest.cc18
1 files changed, 18 insertions, 0 deletions
diff --git a/base/guid_unittest.cc b/base/guid_unittest.cc
index e57eb7e..4eda7f6 100644
--- a/base/guid_unittest.cc
+++ b/base/guid_unittest.cc
@@ -10,6 +10,20 @@
#include "testing/gtest/include/gtest/gtest.h"
#if defined(OS_POSIX)
+
+namespace {
+
+bool IsGUIDv4(const std::string& guid) {
+ // The format of GUID version 4 must be xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx,
+ // where y is one of [8, 9, A, B].
+ return base::IsValidGUID(guid) && guid[14] == '4' &&
+ (guid[19] == '8' || guid[19] == '9' || guid[19] == 'A' ||
+ guid[19] == 'a' || guid[19] == 'B' || guid[19] == 'b');
+}
+
+} // namespace
+
+
TEST(GUIDTest, GUIDGeneratesAllZeroes) {
uint64 bytes[] = { 0, 0 };
std::string clientid = base::RandomDataToGUIDString(bytes);
@@ -41,5 +55,9 @@ TEST(GUIDTest, GUIDBasicUniqueness) {
EXPECT_EQ(36U, guid1.length());
EXPECT_EQ(36U, guid2.length());
EXPECT_NE(guid1, guid2);
+#if defined(OS_POSIX)
+ EXPECT_TRUE(IsGUIDv4(guid1));
+ EXPECT_TRUE(IsGUIDv4(guid2));
+#endif
}
}