summaryrefslogtreecommitdiffstats
path: root/remoting/signaling
diff options
context:
space:
mode:
authorsergeyu <sergeyu@chromium.org>2015-05-06 16:00:16 -0700
committerCommit bot <commit-bot@chromium.org>2015-05-06 23:00:52 +0000
commit8916cd0a41e708d4c00e96dae7960cb9e634794e (patch)
tree69436885a4195f849143207634e2076b4925ea79 /remoting/signaling
parent51bf98859f09d62152a3662839f93b9efad826c5 (diff)
downloadchromium_src-8916cd0a41e708d4c00e96dae7960cb9e634794e.zip
chromium_src-8916cd0a41e708d4c00e96dae7960cb9e634794e.tar.gz
chromium_src-8916cd0a41e708d4c00e96dae7960cb9e634794e.tar.bz2
Normalize JIDs when generating signatures for messages sent to CRD bot.
When generating signatures for the messages sent to the bot the JID must be normalized, i.e. node and domain parts must be in lower-case. XmppSignalStrategy::GetLocalJid() was previously returning normalized value, but it was changed recently, which broke hosts that use account with upper-case characters in the name. BUG=485134 Review URL: https://codereview.chromium.org/1131653002 Cr-Commit-Position: refs/heads/master@{#328646}
Diffstat (limited to 'remoting/signaling')
-rw-r--r--remoting/signaling/jid_util.cc23
-rw-r--r--remoting/signaling/jid_util.h18
-rw-r--r--remoting/signaling/jid_util_unittest.cc19
3 files changed, 60 insertions, 0 deletions
diff --git a/remoting/signaling/jid_util.cc b/remoting/signaling/jid_util.cc
new file mode 100644
index 0000000..8e8e12b
--- /dev/null
+++ b/remoting/signaling/jid_util.cc
@@ -0,0 +1,23 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "remoting/signaling/jid_util.h"
+
+#include "base/strings/string_util.h"
+
+namespace remoting {
+
+std::string NormalizeJid(const std::string& jid) {
+ size_t slash_pos = jid.find('/');
+
+ // In case there the jid doesn't have resource id covert the whole value to
+ // lower-case.
+ if (slash_pos == std::string::npos)
+ return base::StringToLowerASCII(jid);
+
+ return base::StringToLowerASCII(jid.substr(0, slash_pos)) +
+ jid.substr(slash_pos);
+}
+
+} // namespace remoting
diff --git a/remoting/signaling/jid_util.h b/remoting/signaling/jid_util.h
new file mode 100644
index 0000000..e7bd7bc
--- /dev/null
+++ b/remoting/signaling/jid_util.h
@@ -0,0 +1,18 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef REMOTING_SIGNALING_JID_UTIL_H_
+#define REMOTING_SIGNALING_JID_UTIL_H_
+
+#include <string>
+
+namespace remoting {
+
+// Normalizes the |jid| by converting case-insensitive parts (node and domain)
+// to lower-case.
+std::string NormalizeJid(const std::string& jid);
+
+} // namespace remoting
+
+#endif // REMOTING_SIGNALING_JID_UTIL_H_
diff --git a/remoting/signaling/jid_util_unittest.cc b/remoting/signaling/jid_util_unittest.cc
new file mode 100644
index 0000000..c4e307d
--- /dev/null
+++ b/remoting/signaling/jid_util_unittest.cc
@@ -0,0 +1,19 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "remoting/signaling/jid_util.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace remoting {
+
+TEST(JidUtil, NormalizeJid) {
+ EXPECT_EQ(NormalizeJid("USER@DOMAIN.com"), "user@domain.com");
+ EXPECT_EQ(NormalizeJid("user@domain.com"), "user@domain.com");
+ EXPECT_EQ(NormalizeJid("USER@DOMAIN.com/RESOURCE"),
+ "user@domain.com/RESOURCE");
+ EXPECT_EQ(NormalizeJid("USER@DOMAIN.com/"), "user@domain.com/");
+}
+
+} // namespace remoting