16
16
* Authored by: Kevin DuBois <kevin.dubois@canonical.com>
19
#include "mir/graphics/nested_context.h"
19
#include "mir/graphics/platform_authentication.h"
20
20
#include "mir/graphics/platform_operation_message.h"
21
21
#include "src/platforms/mesa/server/kms/nested_authentication.h"
22
22
#include "mir_toolkit/mesa/platform_operation.h"
23
23
#include "mir/test/doubles/mock_drm.h"
24
#include "mir/test/doubles/mock_nested_context.h"
24
#include "mir/test/doubles/mock_platform_authentication.h"
25
25
#include "mir/test/doubles/mock_mesa_auth_extensions.h"
26
26
#include "mir/test/fake_shared.h"
27
27
#include <gtest/gtest.h>
40
40
struct NestedAuthentication : ::testing::Test
42
42
::testing::NiceMock<mtd::MockDRM> mock_drm;
43
mtd::MockNestedContext mock_nested_context;
43
mtd::MockPlatformAuthentication mock_platform_authentication;
44
44
std::shared_ptr<mtd::MockMesaExt> mock_ext = std::make_shared<mtd::MockMesaExt>();
45
45
unsigned int const magic{332211};
49
TEST_F(NestedAuthentication, uses_nested_context_for_auth_magic)
49
TEST_F(NestedAuthentication, uses_platform_authentication_for_auth_magic)
51
51
int const success_response{0};
53
EXPECT_CALL(mock_nested_context, auth_extension())
53
EXPECT_CALL(mock_platform_authentication, auth_extension())
54
54
.WillOnce(Return(mir::optional_value<std::shared_ptr<mg::MesaAuthExtension>>{mock_ext}));
55
55
EXPECT_CALL(*mock_ext, auth_magic(magic))
56
56
.WillOnce(Return(success_response));
58
mgm::NestedAuthentication auth{mt::fake_shared(mock_nested_context)};
58
mgm::NestedAuthentication auth{mt::fake_shared(mock_platform_authentication)};
59
59
auth.auth_magic(magic);
62
62
TEST_F(NestedAuthentication, reports_error_because_of_no_extension)
64
EXPECT_CALL(mock_nested_context, auth_extension())
64
EXPECT_CALL(mock_platform_authentication, auth_extension())
65
65
.WillOnce(Return(mir::optional_value<std::shared_ptr<mg::MesaAuthExtension>>{}));
67
mgm::NestedAuthentication auth{mt::fake_shared(mock_nested_context)};
67
mgm::NestedAuthentication auth{mt::fake_shared(mock_platform_authentication)};
68
68
}, std::runtime_error);
71
71
TEST_F(NestedAuthentication, reports_errors_during_auth_magic)
73
73
int const error_response{-1};
74
EXPECT_CALL(mock_nested_context, auth_extension())
74
EXPECT_CALL(mock_platform_authentication, auth_extension())
75
75
.WillOnce(Return(mir::optional_value<std::shared_ptr<mg::MesaAuthExtension>>{mock_ext}));
76
76
EXPECT_CALL(*mock_ext, auth_magic(magic))
77
77
.WillOnce(Return(error_response));
79
mgm::NestedAuthentication auth{mt::fake_shared(mock_nested_context)};
79
mgm::NestedAuthentication auth{mt::fake_shared(mock_platform_authentication)};
81
81
auth.auth_magic(magic);
82
82
}, std::system_error);
85
TEST_F(NestedAuthentication, uses_nested_context_for_auth_fd)
85
TEST_F(NestedAuthentication, uses_platform_authentication_for_auth_fd)
87
87
int const auth_fd{13};
88
EXPECT_CALL(mock_nested_context, auth_extension())
88
EXPECT_CALL(mock_platform_authentication, auth_extension())
89
89
.WillOnce(Return(mir::optional_value<std::shared_ptr<mg::MesaAuthExtension>>{mock_ext}));
90
90
EXPECT_CALL(*mock_ext, auth_fd())
91
91
.WillOnce(Return(mir::Fd{mir::IntOwnedFd{auth_fd}}));
92
mgm::NestedAuthentication auth{mt::fake_shared(mock_nested_context)};
92
mgm::NestedAuthentication auth{mt::fake_shared(mock_platform_authentication)};
93
93
EXPECT_THAT(auth.authenticated_fd(), Eq(auth_fd));