mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 07:36:10 -04:00
[Nearby Presence] Add authentication status to InitialConnectionInfo
Adds authentication status to `InitialConnectionInfo`, which will pass the result of the authentication to clients when the connection is complete. See go/cros-nearby-presence-np-nc-authentication for details. This is used to communicate the authentication status to clients of RequestConnectionV3(). PiperOrigin-RevId: 613278476
This commit is contained in:
committed by
Copybara-Service
parent
cf2a1eb0b1
commit
ecb9de0cbc
@@ -451,6 +451,8 @@ void ServiceControllerRouter::RequestConnectionV3(
|
||||
response_info.raw_authentication_token.string_data(),
|
||||
.is_incoming_connection =
|
||||
response_info.is_incoming_connection,
|
||||
.authentication_status =
|
||||
response_info.authentication_status,
|
||||
};
|
||||
v3_info.listener.initiated_cb(remote_device, new_info);
|
||||
},
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include "connections/v3/connections_device.h"
|
||||
#include "connections/v3/listening_result.h"
|
||||
#include "connections/v3/params.h"
|
||||
#include "internal/interop/authentication_status.h"
|
||||
#include "internal/flags/nearby_flags.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/condition_variable.h"
|
||||
@@ -278,18 +279,28 @@ class ServiceControllerRouterTest : public testing::Test {
|
||||
v3::ConnectionRequestInfo request_info,
|
||||
ResultCallback callback, bool call_all_cb,
|
||||
bool check_result = true,
|
||||
bool endpoint_info_present = true) {
|
||||
bool endpoint_info_present = true,
|
||||
AuthenticationStatus authentication_status =
|
||||
AuthenticationStatus::kSuccess) {
|
||||
ConnectionResponseInfo response_info{
|
||||
.remote_endpoint_info = ByteArray{"endpoint_name"},
|
||||
.authentication_token = "auth_token",
|
||||
.raw_authentication_token = ByteArray{"auth_token"},
|
||||
.is_incoming_connection = true,
|
||||
.authentication_status = authentication_status,
|
||||
};
|
||||
|
||||
// If we set check_result to false, we expect that RequestConnection will
|
||||
// not be called.
|
||||
if (check_result) {
|
||||
EXPECT_CALL(*mock_, RequestConnectionV3)
|
||||
.WillOnce([call_all_cb, endpoint_info_present, this](
|
||||
.WillOnce([call_all_cb, endpoint_info_present, response_info, this](
|
||||
ClientProxy*, const NearbyDevice&,
|
||||
const ConnectionRequestInfo& info,
|
||||
const ConnectionOptions&) {
|
||||
EXPECT_EQ(info.endpoint_info.Empty(), !endpoint_info_present);
|
||||
if (call_all_cb) {
|
||||
info.listener.initiated_cb(kRemoteEndpointId, {});
|
||||
info.listener.initiated_cb(kRemoteEndpointId, response_info);
|
||||
info.listener.accepted_cb(kRemoteEndpointId);
|
||||
info.listener.rejected_cb(kRemoteEndpointId,
|
||||
Status{Status::kConnectionRejected});
|
||||
@@ -312,12 +323,6 @@ class ServiceControllerRouterTest : public testing::Test {
|
||||
EXPECT_EQ(result_, Status{Status::kSuccess});
|
||||
}
|
||||
}
|
||||
ConnectionResponseInfo response_info{
|
||||
.remote_endpoint_info = ByteArray{"endpoint_name"},
|
||||
.authentication_token = "auth_token",
|
||||
.raw_authentication_token = ByteArray{"auth_token"},
|
||||
.is_incoming_connection = true,
|
||||
};
|
||||
if (client->HasPendingConnectionToEndpoint(kRemoteDevice.GetEndpointId())) {
|
||||
// we are calling this again, and do not need to rerun the below behavior.
|
||||
return;
|
||||
@@ -862,7 +867,9 @@ TEST_F(ServiceControllerRouterTest, RequestConnectionCalledV3) {
|
||||
.listener = {
|
||||
.initiated_cb =
|
||||
[&initiated_latch](const NearbyDevice&,
|
||||
const v3::InitialConnectionInfo&) {
|
||||
const v3::InitialConnectionInfo& info) {
|
||||
EXPECT_EQ(info.authentication_status,
|
||||
AuthenticationStatus::kSuccess);
|
||||
initiated_latch.CountDown();
|
||||
},
|
||||
.result_cb =
|
||||
@@ -892,6 +899,64 @@ TEST_F(ServiceControllerRouterTest, RequestConnectionCalledV3) {
|
||||
EXPECT_TRUE(bandwidth_changed_latch.Await().Ok());
|
||||
}
|
||||
|
||||
TEST_F(ServiceControllerRouterTest,
|
||||
RequestConnectionCalledV3_AuthenticationStatusFail) {
|
||||
// Either Advertising, or Discovery should be ongoing.
|
||||
StartDiscovery(&client_, kServiceId, kDiscoveryOptions, DiscoveryListener{},
|
||||
[this](Status status) {
|
||||
MutexLock lock(&mutex_);
|
||||
result_ = status;
|
||||
complete_ = true;
|
||||
cond_.Notify();
|
||||
});
|
||||
// Establish connection.
|
||||
auto local_device =
|
||||
v3::ConnectionsDevice(client_.GetLocalEndpointId(), kRequestorName, {});
|
||||
// Testing callback wrapping as well.
|
||||
CountDownLatch initiated_latch(1);
|
||||
CountDownLatch result_latch(2);
|
||||
CountDownLatch disconnected_latch(1);
|
||||
CountDownLatch bandwidth_changed_latch(1);
|
||||
|
||||
RequestConnectionV3(
|
||||
&client_, kRemoteDevice,
|
||||
v3::ConnectionRequestInfo{
|
||||
.local_device = local_device,
|
||||
.listener = {
|
||||
.initiated_cb =
|
||||
[&initiated_latch](const NearbyDevice&,
|
||||
const v3::InitialConnectionInfo& info) {
|
||||
EXPECT_EQ(info.authentication_status,
|
||||
AuthenticationStatus::kFailure);
|
||||
initiated_latch.CountDown();
|
||||
},
|
||||
.result_cb =
|
||||
[&result_latch](const NearbyDevice&, v3::ConnectionResult) {
|
||||
result_latch.CountDown();
|
||||
},
|
||||
.disconnected_cb =
|
||||
[&disconnected_latch](const NearbyDevice&) {
|
||||
disconnected_latch.CountDown();
|
||||
},
|
||||
.bandwidth_changed_cb =
|
||||
[&bandwidth_changed_latch](const NearbyDevice&,
|
||||
v3::BandwidthInfo) {
|
||||
bandwidth_changed_latch.CountDown();
|
||||
}},
|
||||
},
|
||||
[this](Status status) {
|
||||
MutexLock lock(&mutex_);
|
||||
result_ = status;
|
||||
complete_ = true;
|
||||
cond_.Notify();
|
||||
},
|
||||
true, true, true, AuthenticationStatus::kFailure);
|
||||
EXPECT_TRUE(initiated_latch.Await().Ok());
|
||||
EXPECT_TRUE(result_latch.Await().Ok());
|
||||
EXPECT_TRUE(disconnected_latch.Await().Ok());
|
||||
EXPECT_TRUE(bandwidth_changed_latch.Await().Ok());
|
||||
}
|
||||
|
||||
TEST_F(ServiceControllerRouterTest, RequestConnectionV3FakeDevice) {
|
||||
// Either Advertising, or Discovery should be ongoing.
|
||||
StartDiscovery(&client_, kServiceId, kDiscoveryOptions, DiscoveryListener{},
|
||||
|
||||
@@ -22,6 +22,7 @@ cc_library(
|
||||
"//connections:core_types",
|
||||
"//connections/implementation/proto:offline_wire_formats_cc_proto",
|
||||
"//internal/crypto_cros",
|
||||
"//internal/interop:authentication_status",
|
||||
"//internal/interop:device",
|
||||
"//internal/platform:connection_info",
|
||||
"//proto:connections_enums_cc_proto",
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "connections/status.h"
|
||||
#include "internal/interop/authentication_status.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
@@ -35,6 +36,9 @@ struct InitialConnectionInfo {
|
||||
std::string raw_authentication_token;
|
||||
// Specifies if the connection is incoming or outgoing.
|
||||
bool is_incoming_connection = false;
|
||||
// Result of authentication via the DeviceProvider, if available. Only used
|
||||
// for `RequestConnectionV3()`.
|
||||
AuthenticationStatus authentication_status = AuthenticationStatus::kUnknown;
|
||||
};
|
||||
|
||||
} // namespace v3
|
||||
|
||||
Reference in New Issue
Block a user