From 8916cd0a41e708d4c00e96dae7960cb9e634794e Mon Sep 17 00:00:00 2001 From: sergeyu Date: Wed, 6 May 2015 16:00:16 -0700 Subject: 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} --- remoting/signaling/jid_util.cc | 23 +++++++++++++++++++++++ remoting/signaling/jid_util.h | 18 ++++++++++++++++++ remoting/signaling/jid_util_unittest.cc | 19 +++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 remoting/signaling/jid_util.cc create mode 100644 remoting/signaling/jid_util.h create mode 100644 remoting/signaling/jid_util_unittest.cc (limited to 'remoting/signaling') 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 + +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 -- cgit v1.1