~ubuntu-branches/ubuntu/vivid/mir/vivid

« back to all changes in this revision

Viewing changes to tests/acceptance-tests/test_client_authorization.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release, Daniel van Vugt, Ubuntu daily release
  • Date: 2014-08-29 16:12:54 UTC
  • mfrom: (1.1.73)
  • Revision ID: package-import@ubuntu.com-20140829161254-wfnunk4fw3msth3c
Tags: 0.7.0+14.10.20140829-0ubuntu1
[ Daniel van Vugt ]
* New upstream release 0.7.0 (https://launchpad.net/mir/+milestone/0.7.0)
  - Enhancements:
    . Test suite: Reworked mechanism to override Mir client functions
    . Demo shell: Detect custom rendering (decorations) to make it
      compatible with overlay optimizations
    . Make sure to preserve fd resources until the end of the sending
      of the message
    . Add test cases and script for tracking changes to the new ABIs:
      libmircommon, libmirplatform
    . Symbols file for libmirplatform
    . Symbols file for libmircommon
    . Symbols file for libmirserver
    . Various improvements to the SessionMediator test
    . Various build related improvements
    . Print testcase output during package build
    . Abort test when InProcessServer startup fails
    . Link the integration and unit tests against the server objects
    . Add a document detailing the useful tests to run and the useful
      logs to collect when troubleshooting a new android chipset
    . Enable motion event resampling and prediction for a more responsive
      touch experience.
  - ABI summary: Servers need rebuilding, but clients do not
    . Mirclient ABI unchanged at 8
    . Mircommon ABI bumped to 1
    . Mirplatform ABI bumped to 2
    . Mirserver ABI bumped to 25
  - API changes
    . Deleted function - frontend::Shell::create_surface_for(). If you have
      the std::shared_ptr<frontend::Session> session, you can just do
      session->create_surface(params) instead to get a SurfaceId
  - Bug fixes:
    . Ensure we process lifecycle events before the nested server is torn
      down (LP: #1353465)
    . Fix race in InputTestingServerConfiguration (LP: #1354446)
    . Fix fd leaks in prompt session frontend code and tests (LP: #1353461)
    . Detect the additional things the demo shell draws on the renderable
      list and avoid calling the optimized post function if they are being
      drawn (LP: #1348330)
    . Client: Fix SIGTERM dispatch in our default lifecycle event handler
      (LP: #1353867)
    . DemoRenderer: Don't try to create a texture of width zero. 
      (LP: #1358210)
    . Fix CI failures (LP: #1358698)
    . Fix build failure: "variable ‘rc’ set but not used" which happens in
      release mode when NDEBUG is set (LP: #1358625)
    . Only enumerate exposed input surfaces to avoid delivering events to
      occluded surfaces (LP: #1359264)
    . Android: do not post driver cancelled buffers (LP: #1359406)
    . Client: Ensure our platform library stays loaded for as long as it is
      needed by other objects (LP: #1358191)
    . Examples: Register the DemoCompositor with the Scene to properly
      process visibility events (LP: #1359487)
    . Mir_demo_client_basic: Don't assert on user errors like failing to
      connect to a Mir server (LP: #1331958)
    . Tests: Explicitly depend on GMock target to avoid build races
      (LP: #1362646)

[ Ubuntu daily release ]
* New rebuild forced

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
#include "mir_test/fake_shared.h"
25
25
#include "mir_test_framework/display_server_test_fixture.h"
 
26
#include "mir_test_doubles/stub_session_authorizer.h"
26
27
 
27
28
#include <gtest/gtest.h>
28
29
#include <gmock/gmock.h>
36
37
namespace mf = mir::frontend;
37
38
namespace mt = mir::test;
38
39
namespace mtf = mir_test_framework;
39
 
 
40
 
namespace
41
 
{
42
 
    char const* const mir_test_socket = mtf::test_socket_file().c_str();
43
 
}
44
 
 
45
 
namespace
46
 
{
47
 
struct ConnectingClient : TestingClientConfiguration
48
 
{
49
 
    MirConnection *connection;
50
 
    void exec()
51
 
    {
52
 
        connection = mir_connect_sync(
53
 
            mir_test_socket,
54
 
            __PRETTY_FUNCTION__);
55
 
        mir_connection_release(connection);
56
 
    }
57
 
};
 
40
namespace mtd = mir::test::doubles;
 
41
 
 
42
namespace
 
43
{
 
44
char const* const mir_test_socket = mtf::test_socket_file().c_str();
58
45
 
59
46
struct ClientCredsTestFixture : BespokeDisplayServerTestFixture
60
47
{
144
131
                screencast_is_allowed(Truly(matches_creds)))
145
132
                .Times(1)
146
133
                .WillOnce(Return(false));
 
134
            EXPECT_CALL(mock_authorizer,
 
135
                prompt_session_is_allowed(Truly(matches_creds)))
 
136
                .Times(1)
 
137
                .WillOnce(Return(false));
147
138
            connect_sync.try_signal_ready_for();
148
139
        }
149
140
 
159
150
    launch_server_process(server_config);
160
151
 
161
152
 
162
 
    struct ClientConfiguration : ConnectingClient
 
153
    struct ClientConfiguration : TestingClientConfiguration
163
154
    {
164
155
        ClientConfiguration(ClientCredsTestFixture::SharedRegion *shared_region,
165
156
                            mtf::CrossProcessSync const& connect_sync)
172
163
        {
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);
176
169
        }
177
170
 
178
171
        ClientCredsTestFixture::SharedRegion* shared_region;
181
174
    launch_client_process(client_config);
182
175
}
183
176
 
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)
188
179
{
189
180
    using namespace ::testing;
190
181
 
191
182
    struct ServerConfiguration : TestingServerConfiguration
192
183
    {
193
 
        ServerConfiguration(ClientCredsTestFixture::SharedRegion *shared_region)
194
 
            : shared_region(shared_region)
195
 
        {
196
 
        }
197
 
 
198
 
        void exec() override
199
 
        {
200
 
            using namespace ::testing;
201
 
 
202
 
            EXPECT_TRUE(shared_region->wait_for_client_creds());
203
 
            auto matches_creds = [&](mf::SessionCredentials const& creds)
204
 
            {
205
 
                return shared_region->matches_client_process_creds(creds);
206
 
            };
207
 
 
208
 
            EXPECT_CALL(mock_authorizer,
209
 
                connection_is_allowed(Truly(matches_creds)))
210
 
                .Times(1)
211
 
                .WillOnce(Return(false));
212
 
        }
213
 
 
214
184
        std::shared_ptr<mf::SessionAuthorizer> the_session_authorizer() override
215
185
        {
216
 
            return mt::fake_shared(mock_authorizer);
 
186
            struct StubAuthorizer : mtd::StubSessionAuthorizer
 
187
            {
 
188
                bool connection_is_allowed(mir::frontend::SessionCredentials const&) override
 
189
                {
 
190
                    return false;
 
191
                }
 
192
            };
 
193
 
 
194
            return std::make_shared<StubAuthorizer>();
217
195
        }
 
196
    } server_config;
218
197
 
219
 
        ClientCredsTestFixture::SharedRegion* shared_region;
220
 
        MockSessionAuthorizer mock_authorizer;
221
 
    } server_config(shared_region);
222
198
    launch_server_process(server_config);
223
199
 
224
 
 
225
 
    struct ClientConfiguration : ConnectingClient
 
200
    struct ClientConfiguration : TestingClientConfiguration
226
201
    {
227
 
        ClientConfiguration(ClientCredsTestFixture::SharedRegion *shared_region)
228
 
            : shared_region(shared_region)
229
 
        {
230
 
        }
231
 
 
232
202
        void exec() override
233
203
        {
234
 
            shared_region->post_client_creds();
235
 
 
236
 
            connection = mir_connect_sync(
237
 
                mir_test_socket,
238
 
                __PRETTY_FUNCTION__);
239
 
 
240
 
            MirSurfaceParameters const parameters =
241
 
            {
242
 
                __PRETTY_FUNCTION__,
243
 
                1, 1,
244
 
                mir_pixel_format_abgr_8888,
245
 
                mir_buffer_usage_hardware,
246
 
                mir_display_output_id_invalid
247
 
            };
248
 
            mir_connection_create_surface_sync(connection, &parameters);
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);
251
207
        }
252
 
 
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
256
 
        {
257
 
            return true;
258
 
        }
259
 
 
260
 
        ClientCredsTestFixture::SharedRegion* shared_region;
261
 
    } client_config(shared_region);
 
208
    } client_config;
 
209
 
262
210
    launch_client_process(client_config);
263
211
}