36
37
namespace mf = mir::frontend;
37
38
namespace mt = mir::test;
38
39
namespace mtf = mir_test_framework;
42
char const* const mir_test_socket = mtf::test_socket_file().c_str();
47
struct ConnectingClient : TestingClientConfiguration
49
MirConnection *connection;
52
connection = mir_connect_sync(
55
mir_connection_release(connection);
40
namespace mtd = mir::test::doubles;
44
char const* const mir_test_socket = mtf::test_socket_file().c_str();
59
46
struct ClientCredsTestFixture : BespokeDisplayServerTestFixture
173
164
shared_region->post_client_creds();
174
165
connect_sync.wait_for_signal_ready_for();
175
ConnectingClient::exec();
166
auto const connection = mir_connect_sync(mir_test_socket, __PRETTY_FUNCTION__);
167
EXPECT_TRUE(mir_connection_is_valid(connection));
168
mir_connection_release(connection);
178
171
ClientCredsTestFixture::SharedRegion* shared_region;
181
174
launch_client_process(client_config);
184
// TODO this test exposes a race condition when the client processes both an error
185
// TODO from connect and the socket being dropped. RAOF is doing some rework that
186
// TODO should fix this a side effect. It should be re-enabled when that is done.
187
TEST_F(ClientCredsTestFixture, DISABLED_authorizer_may_prevent_connection_of_clients)
177
// This test is also a regression test for https://bugs.launchpad.net/mir/+bug/1358191
178
TEST_F(ClientCredsTestFixture, authorizer_may_prevent_connection_of_clients)
189
180
using namespace ::testing;
191
182
struct ServerConfiguration : TestingServerConfiguration
193
ServerConfiguration(ClientCredsTestFixture::SharedRegion *shared_region)
194
: shared_region(shared_region)
200
using namespace ::testing;
202
EXPECT_TRUE(shared_region->wait_for_client_creds());
203
auto matches_creds = [&](mf::SessionCredentials const& creds)
205
return shared_region->matches_client_process_creds(creds);
208
EXPECT_CALL(mock_authorizer,
209
connection_is_allowed(Truly(matches_creds)))
211
.WillOnce(Return(false));
214
184
std::shared_ptr<mf::SessionAuthorizer> the_session_authorizer() override
216
return mt::fake_shared(mock_authorizer);
186
struct StubAuthorizer : mtd::StubSessionAuthorizer
188
bool connection_is_allowed(mir::frontend::SessionCredentials const&) override
194
return std::make_shared<StubAuthorizer>();
219
ClientCredsTestFixture::SharedRegion* shared_region;
220
MockSessionAuthorizer mock_authorizer;
221
} server_config(shared_region);
222
198
launch_server_process(server_config);
225
struct ClientConfiguration : ConnectingClient
200
struct ClientConfiguration : TestingClientConfiguration
227
ClientConfiguration(ClientCredsTestFixture::SharedRegion *shared_region)
228
: shared_region(shared_region)
232
202
void exec() override
234
shared_region->post_client_creds();
236
connection = mir_connect_sync(
238
__PRETTY_FUNCTION__);
240
MirSurfaceParameters const parameters =
244
mir_pixel_format_abgr_8888,
245
mir_buffer_usage_hardware,
246
mir_display_output_id_invalid
248
mir_connection_create_surface_sync(connection, ¶meters);
249
EXPECT_GT(strlen(mir_connection_get_error_message(connection)), static_cast<unsigned int>(0));
204
auto const connection = mir_connect_sync(mir_test_socket, __PRETTY_FUNCTION__);
205
EXPECT_FALSE(mir_connection_is_valid(connection));
250
206
mir_connection_release(connection);
253
//we are testing the connect function itself, without getting to the
254
// point where drivers are used, so force using production config
255
bool use_real_graphics(mir::options::Option const&) override
260
ClientCredsTestFixture::SharedRegion* shared_region;
261
} client_config(shared_region);
262
210
launch_client_process(client_config);