-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathauth_requestor_auto_test.go
More file actions
476 lines (386 loc) · 19.3 KB
/
Copy pathauth_requestor_auto_test.go
File metadata and controls
476 lines (386 loc) · 19.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
// -*- Mode: Go; indent-tabs-mode: t -*-
/*
* Copyright (C) 2026 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package secboot_test
import (
"bytes"
"context"
"errors"
"fmt"
"io"
"strings"
. "github.com/snapcore/secboot"
"github.com/snapcore/secboot/internal/testutil"
snapd_testutil "github.com/snapcore/snapd/testutil"
. "gopkg.in/check.v1"
)
type authRequestorAutoSuite struct {
snapd_testutil.BaseTest
authRequestorPlymouthTestMixin
authRequestorSystemdTestMixin
}
func (s *authRequestorAutoSuite) SetUpTest(c *C) {
s.AddCleanup(s.authRequestorPlymouthTestMixin.setUpTest(c))
s.AddCleanup(s.authRequestorSystemdTestMixin.setUpTest(c))
}
func (s *authRequestorAutoSuite) setPassphrase(c *C, passphrase string) {
s.authRequestorPlymouthTestMixin.setPassphrase(c, passphrase)
s.authRequestorSystemdTestMixin.setPassphrase(c, passphrase)
}
var _ = Suite(&authRequestorAutoSuite{})
type mockAutoAuthRequestorStringer struct {
err error
}
func (s *mockAutoAuthRequestorStringer) RequestUserCredentialString(name, path string, authType UserAuthType) (string, error) {
if s.err != nil {
return "", s.err
}
var fmtString string
switch authType {
case UserAuthTypePassphrase:
fmtString = "Enter passphrase for %s (%s):"
case UserAuthTypePIN:
fmtString = "Enter PIN for %s (%s):"
case UserAuthTypeRecoveryKey:
fmtString = "Enter recovery key for %s (%s):"
case UserAuthTypePassphrase | UserAuthTypePIN:
fmtString = "Enter passphrase or PIN for %s (%s):"
case UserAuthTypePassphrase | UserAuthTypeRecoveryKey:
fmtString = "Enter passphrase or recovery key for %s (%s):"
case UserAuthTypePIN | UserAuthTypeRecoveryKey:
fmtString = "Enter PIN or recovery key for %s (%s):"
case UserAuthTypePassphrase | UserAuthTypePIN | UserAuthTypeRecoveryKey:
fmtString = "Enter passphrase, PIN or recovery key for %s (%s):"
default:
return "", errors.New("unexpected UserAuthType")
}
return fmt.Sprintf(fmtString, name, path), nil
}
func (s *mockAutoAuthRequestorStringer) NotifyUserAuthResultString(name, path string, result UserAuthResult, authTypes, unavailableAuthTypes UserAuthType) (string, error) {
if s.err != nil {
return "", s.err
}
switch result {
case UserAuthResultSuccess:
var fmtString string
switch authTypes {
case UserAuthTypePassphrase:
fmtString = "Unlocked %s (%s) successfully with passphrase"
case UserAuthTypePIN:
fmtString = "Unlocked %s (%s) successfully with PIN"
case UserAuthTypeRecoveryKey:
fmtString = "Unlocked %s (%s) successfully with recovery key"
default:
return "", errors.New("unexpected UserAuthType")
}
return fmt.Sprintf(fmtString, name, path), nil
case UserAuthResultFailed:
var b strings.Builder
switch authTypes {
case UserAuthTypePassphrase:
io.WriteString(&b, "Incorrect passphrase")
case UserAuthTypePIN:
io.WriteString(&b, "Incorrect PIN")
case UserAuthTypeRecoveryKey:
io.WriteString(&b, "Incorrect recovery key")
case UserAuthTypePassphrase | UserAuthTypePIN:
io.WriteString(&b, "Incorrect passphrase or PIN")
case UserAuthTypePassphrase | UserAuthTypeRecoveryKey:
io.WriteString(&b, "Incorrect passphrase or recovery key")
case UserAuthTypePIN | UserAuthTypeRecoveryKey:
io.WriteString(&b, "Incorrect PIN or recovery key")
case UserAuthTypePassphrase | UserAuthTypePIN | UserAuthTypeRecoveryKey:
io.WriteString(&b, "Incorrect passphrase, PIN or recovery key")
default:
return "", errors.New("unexpected UserAuthType")
}
switch unavailableAuthTypes {
case UserAuthType(0):
case UserAuthTypePassphrase:
io.WriteString(&b, ". No more passphrase tries remaining")
case UserAuthTypePIN:
io.WriteString(&b, ". No more PIN tries remaining")
case UserAuthTypeRecoveryKey:
io.WriteString(&b, ". No more recovery key tries remaining")
case UserAuthTypePassphrase | UserAuthTypePIN:
io.WriteString(&b, ". No more passphrase or PIN tries remaining")
case UserAuthTypePassphrase | UserAuthTypeRecoveryKey:
io.WriteString(&b, ". No more passphrase or recovery key tries remaining")
case UserAuthTypePIN | UserAuthTypeRecoveryKey:
io.WriteString(&b, ". No more PIN or recovery key tries remaining")
case UserAuthTypePassphrase | UserAuthTypePIN | UserAuthTypeRecoveryKey:
io.WriteString(&b, ". No more passphrase, PIN or recovery key tries remaining")
default:
return "", errors.New("unexpected UserAuthType")
}
return b.String(), nil
case UserAuthResultInvalidFormat:
switch authTypes {
case UserAuthTypePIN:
return "Invalid PIN", nil
case UserAuthTypeRecoveryKey:
return "Invalid recovery key", nil
case UserAuthTypePIN | UserAuthTypeRecoveryKey:
return "Invalid PIN or recovery key", nil
default:
return "", errors.New("unexpected UserAuthType")
}
default:
return "", errors.New("unexpected UserAuthResult")
}
}
func (s *authRequestorAutoSuite) TestNewAuthRequestor(c *C) {
sdConsole := new(bytes.Buffer)
restore := MockNewSystemdAuthRequestor(func(console io.Writer, stringFn SystemdAuthRequestorStringFn) (AuthRequestor, error) {
c.Check(console, Equals, sdConsole)
return NewSystemdAuthRequestor(console, stringFn)
})
defer restore()
requestor, err := NewAutoAuthRequestor(sdConsole, new(mockAutoAuthRequestorStringer))
c.Assert(err, IsNil)
c.Assert(requestor, NotNil)
c.Assert(requestor, testutil.ConvertibleTo, &AutoAuthRequestor{})
c.Assert(requestor.(*AutoAuthRequestor).Requestors(), HasLen, 2)
c.Check(requestor.(*AutoAuthRequestor).Requestors()[0], testutil.ConvertibleTo, &PlymouthAuthRequestor{})
c.Check(requestor.(*AutoAuthRequestor).Requestors()[1], testutil.ConvertibleTo, &SystemdAuthRequestor{})
}
func (s *authRequestorAutoSuite) TestNewAuthRequestorPlymouthNotAvailable(c *C) {
restore := MockNewPlymouthAuthRequestor(func(_ AuthRequestorStringer) (AuthRequestor, error) {
return nil, ErrAuthRequestorNotAvailable
})
defer restore()
requestor, err := NewAutoAuthRequestor(nil, new(mockAutoAuthRequestorStringer))
c.Assert(err, IsNil)
c.Assert(requestor, NotNil)
c.Assert(requestor, testutil.ConvertibleTo, &AutoAuthRequestor{})
c.Assert(requestor.(*AutoAuthRequestor).Requestors(), HasLen, 1)
c.Check(requestor.(*AutoAuthRequestor).Requestors()[0], testutil.ConvertibleTo, &SystemdAuthRequestor{})
}
func (s *authRequestorAutoSuite) TestNewAuthRequestorSystemdNotAvailable(c *C) {
restore := MockNewSystemdAuthRequestor(func(_ io.Writer, _ SystemdAuthRequestorStringFn) (AuthRequestor, error) {
return nil, ErrAuthRequestorNotAvailable
})
defer restore()
requestor, err := NewAutoAuthRequestor(nil, new(mockAutoAuthRequestorStringer))
c.Assert(err, IsNil)
c.Assert(requestor, NotNil)
c.Assert(requestor, testutil.ConvertibleTo, &AutoAuthRequestor{})
c.Assert(requestor.(*AutoAuthRequestor).Requestors(), HasLen, 1)
c.Check(requestor.(*AutoAuthRequestor).Requestors()[0], testutil.ConvertibleTo, &PlymouthAuthRequestor{})
}
func (s *authRequestorAutoSuite) TestNewAuthRequestorNotAvailable(c *C) {
restore := MockNewPlymouthAuthRequestor(func(_ AuthRequestorStringer) (AuthRequestor, error) {
return nil, ErrAuthRequestorNotAvailable
})
defer restore()
restore = MockNewSystemdAuthRequestor(func(_ io.Writer, _ SystemdAuthRequestorStringFn) (AuthRequestor, error) {
return nil, ErrAuthRequestorNotAvailable
})
defer restore()
_, err := NewAutoAuthRequestor(nil, new(mockAutoAuthRequestorStringer))
c.Check(err, ErrorMatches, "the auth requestor is not available")
c.Check(errors.Is(err, ErrAuthRequestorNotAvailable), testutil.IsTrue)
}
func (s *authRequestorAutoSuite) TestNewAuthRequestorPlymouthError(c *C) {
_, err := NewAutoAuthRequestor(nil, nil)
c.Check(err, ErrorMatches, "cannot create Plymouth AuthRequestor: must supply an implementation of AuthRequestorStringer")
}
func (s *authRequestorAutoSuite) TestNewAuthRequestorSystemdError(c *C) {
restore := MockNewSystemdAuthRequestor(func(_ io.Writer, _ SystemdAuthRequestorStringFn) (AuthRequestor, error) {
return nil, errors.New("some error")
})
defer restore()
_, err := NewAutoAuthRequestor(nil, new(mockAutoAuthRequestorStringer))
c.Check(err, ErrorMatches, "cannot create systemd AuthRequestor: some error")
}
func (s *authRequestorAutoSuite) TestRequestUserCredentialPlymouth(c *C) {
// Ensure that plymouth is used first if available.
s.setPassphrase(c, "password")
requestor, err := NewAutoAuthRequestor(nil, new(mockAutoAuthRequestorStringer))
c.Assert(err, IsNil)
passphrase, passphraseType, err := requestor.RequestUserCredential(context.Background(), "data", "/dev/sda1", UserAuthTypePassphrase)
c.Check(err, IsNil)
c.Check(passphrase, Equals, "password")
c.Check(passphraseType, Equals, UserAuthTypePassphrase)
c.Check(s.mockPlymouth.Calls(), DeepEquals, [][]string{
{"plymouth", "--ping"},
{"plymouth", "ask-for-password", "--prompt", "Enter passphrase for data (/dev/sda1):"},
})
c.Check(s.mockSdAskPassword.Calls(), HasLen, 0)
c.Assert(requestor, testutil.ConvertibleTo, &AutoAuthRequestor{})
c.Check(requestor.(*AutoAuthRequestor).LastUsed(), testutil.ConvertibleTo, &PlymouthAuthRequestor{})
}
func (s *authRequestorAutoSuite) TestRequestUserCredentialSystemd(c *C) {
// Ensure that systemd-ask-password is used if plymouth isn't running.
s.setPassphrase(c, "password")
s.stopPlymouthd(c)
requestor, err := NewAutoAuthRequestor(nil, new(mockAutoAuthRequestorStringer))
c.Assert(err, IsNil)
passphrase, passphraseType, err := requestor.RequestUserCredential(context.Background(), "data", "/dev/sda1", UserAuthTypePassphrase)
c.Check(err, IsNil)
c.Check(passphrase, Equals, "password")
c.Check(passphraseType, Equals, UserAuthTypePassphrase)
c.Check(s.mockPlymouth.Calls(), DeepEquals, [][]string{{"plymouth", "--ping"}})
c.Check(s.mockSdAskPassword.Calls(), DeepEquals, [][]string{{"systemd-ask-password", "--icon", "drive-harddisk", "--id", "secboot.test:/dev/sda1", "Enter passphrase for data (/dev/sda1):"}})
c.Assert(requestor, testutil.ConvertibleTo, &AutoAuthRequestor{})
c.Check(requestor.(*AutoAuthRequestor).LastUsed(), testutil.ConvertibleTo, &SystemdAuthRequestor{})
}
func (s *authRequestorAutoSuite) TestRequestUserCredentialDifferentName(c *C) {
s.setPassphrase(c, "password")
requestor, err := NewAutoAuthRequestor(nil, new(mockAutoAuthRequestorStringer))
c.Assert(err, IsNil)
passphrase, passphraseType, err := requestor.RequestUserCredential(context.Background(), "foo", "/dev/sda1", UserAuthTypePassphrase)
c.Check(err, IsNil)
c.Check(passphrase, Equals, "password")
c.Check(passphraseType, Equals, UserAuthTypePassphrase)
c.Check(s.mockPlymouth.Calls(), DeepEquals, [][]string{
{"plymouth", "--ping"},
{"plymouth", "ask-for-password", "--prompt", "Enter passphrase for foo (/dev/sda1):"},
})
c.Check(s.mockSdAskPassword.Calls(), HasLen, 0)
c.Assert(requestor, testutil.ConvertibleTo, &AutoAuthRequestor{})
c.Check(requestor.(*AutoAuthRequestor).LastUsed(), testutil.ConvertibleTo, &PlymouthAuthRequestor{})
}
func (s *authRequestorAutoSuite) TestRequestUserCredentialDifferentPath(c *C) {
s.setPassphrase(c, "password")
requestor, err := NewAutoAuthRequestor(nil, new(mockAutoAuthRequestorStringer))
c.Assert(err, IsNil)
passphrase, passphraseType, err := requestor.RequestUserCredential(context.Background(), "data", "/dev/nvme0n1p3", UserAuthTypePassphrase)
c.Check(err, IsNil)
c.Check(passphrase, Equals, "password")
c.Check(passphraseType, Equals, UserAuthTypePassphrase)
c.Check(s.mockPlymouth.Calls(), DeepEquals, [][]string{
{"plymouth", "--ping"},
{"plymouth", "ask-for-password", "--prompt", "Enter passphrase for data (/dev/nvme0n1p3):"},
})
c.Check(s.mockSdAskPassword.Calls(), HasLen, 0)
c.Assert(requestor, testutil.ConvertibleTo, &AutoAuthRequestor{})
c.Check(requestor.(*AutoAuthRequestor).LastUsed(), testutil.ConvertibleTo, &PlymouthAuthRequestor{})
}
func (s *authRequestorAutoSuite) TestRequestUserCredentialDifferentCredentialType(c *C) {
s.setPassphrase(c, "password")
requestor, err := NewAutoAuthRequestor(nil, new(mockAutoAuthRequestorStringer))
c.Assert(err, IsNil)
passphrase, passphraseType, err := requestor.RequestUserCredential(context.Background(), "foo", "/dev/sda1", UserAuthTypePassphrase|UserAuthTypeRecoveryKey)
c.Check(err, IsNil)
c.Check(passphrase, Equals, "password")
c.Check(passphraseType, Equals, UserAuthTypePassphrase|UserAuthTypeRecoveryKey)
c.Check(s.mockPlymouth.Calls(), DeepEquals, [][]string{
{"plymouth", "--ping"},
{"plymouth", "ask-for-password", "--prompt", "Enter passphrase or recovery key for foo (/dev/sda1):"},
})
c.Check(s.mockSdAskPassword.Calls(), HasLen, 0)
c.Assert(requestor, testutil.ConvertibleTo, &AutoAuthRequestor{})
c.Check(requestor.(*AutoAuthRequestor).LastUsed(), testutil.ConvertibleTo, &PlymouthAuthRequestor{})
}
func (s *authRequestorAutoSuite) TestRequestUserCredentialDifferentPassphrase(c *C) {
s.setPassphrase(c, "1234")
requestor, err := NewAutoAuthRequestor(nil, new(mockAutoAuthRequestorStringer))
c.Assert(err, IsNil)
passphrase, passphraseType, err := requestor.RequestUserCredential(context.Background(), "data", "/dev/sda1", UserAuthTypePassphrase)
c.Check(err, IsNil)
c.Check(passphrase, Equals, "1234")
c.Check(passphraseType, Equals, UserAuthTypePassphrase)
c.Check(s.mockPlymouth.Calls(), DeepEquals, [][]string{
{"plymouth", "--ping"},
{"plymouth", "ask-for-password", "--prompt", "Enter passphrase for data (/dev/sda1):"},
})
c.Check(s.mockSdAskPassword.Calls(), HasLen, 0)
c.Assert(requestor, testutil.ConvertibleTo, &AutoAuthRequestor{})
c.Check(requestor.(*AutoAuthRequestor).LastUsed(), testutil.ConvertibleTo, &PlymouthAuthRequestor{})
}
func (s *authRequestorAutoSuite) TestRequestUserCredentialCanceledContext(c *C) {
s.setPassphrase(c, "password")
requestor, err := NewAutoAuthRequestor(nil, new(mockAutoAuthRequestorStringer))
c.Assert(err, IsNil)
ctx, cancel := context.WithCancel(context.Background())
cancel()
_, _, err = requestor.RequestUserCredential(ctx, "data", "/dev/sda1", UserAuthTypePassphrase)
c.Check(err, ErrorMatches, `cannot execute plymouth --ping: context canceled`)
c.Check(errors.Is(err, context.Canceled), testutil.IsTrue)
}
func (s *authRequestorAutoSuite) TestRequestUserCredentialPlymouthFails(c *C) {
// Ensure we get an error if any implementation fails with an unexpected error.
s.authRequestorSystemdTestMixin.setPassphrase(c, "password")
requestor, err := NewAutoAuthRequestor(nil, new(mockAutoAuthRequestorStringer))
c.Assert(err, IsNil)
_, _, err = requestor.RequestUserCredential(context.Background(), "data", "/dev/sda1", UserAuthTypePassphrase)
c.Check(err, ErrorMatches, "cannot execute plymouth ask-for-password: exit status 1")
}
func (s *authRequestorAutoSuite) TestRequestUserCredentialNotAvailable(c *C) {
// Ensure we get an appropriate error if no auth requestor is available.
s.stopPlymouthd(c)
restore := MockNewSystemdAuthRequestor(func(_ io.Writer, _ SystemdAuthRequestorStringFn) (AuthRequestor, error) {
return nil, ErrAuthRequestorNotAvailable
})
defer restore()
requestor, err := NewAutoAuthRequestor(nil, new(mockAutoAuthRequestorStringer))
c.Assert(err, IsNil)
_, _, err = requestor.RequestUserCredential(context.Background(), "data", "/dev/sda1", UserAuthTypePassphrase)
c.Check(err, ErrorMatches, "the auth requestor is not available")
c.Check(errors.Is(err, ErrAuthRequestorNotAvailable), testutil.IsTrue)
}
func (s *authRequestorAutoSuite) TestNotifyUserAuthResult(c *C) {
requestor := NewAutoAuthRequestorForTesting(nil, NewPlymouthAuthRequestorForTesting(new(mockPlymouthAuthRequestorStringer), &PlymouthRequestUserCredentialContext{Name: "data", Path: "/dev/sda1"}))
c.Check(requestor.NotifyUserAuthResult(context.Background(), UserAuthResultSuccess, UserAuthTypePassphrase, 0), IsNil)
c.Check(s.mockPlymouth.Calls(), DeepEquals, [][]string{
{"plymouth", "--ping"},
{"plymouth", "display-message", "--text", "Unlocked data (/dev/sda1) successfully with passphrase"},
})
}
func (s *authRequestorAutoSuite) TestNotifyUserAuthResultDifferentResult(c *C) {
requestor := NewAutoAuthRequestorForTesting(nil, NewPlymouthAuthRequestorForTesting(new(mockPlymouthAuthRequestorStringer), &PlymouthRequestUserCredentialContext{Name: "data", Path: "/dev/sda1"}))
c.Check(requestor.NotifyUserAuthResult(context.Background(), UserAuthResultFailed, UserAuthTypePassphrase, 0), IsNil)
c.Check(s.mockPlymouth.Calls(), DeepEquals, [][]string{
{"plymouth", "--ping"},
{"plymouth", "display-message", "--text", "Incorrect passphrase"},
})
}
func (s *authRequestorAutoSuite) TestNotifyUserAuthResultDifferentAuthType(c *C) {
requestor := NewAutoAuthRequestorForTesting(nil, NewPlymouthAuthRequestorForTesting(new(mockPlymouthAuthRequestorStringer), &PlymouthRequestUserCredentialContext{Name: "data", Path: "/dev/sda1"}))
c.Check(requestor.NotifyUserAuthResult(context.Background(), UserAuthResultSuccess, UserAuthTypePIN, 0), IsNil)
c.Check(s.mockPlymouth.Calls(), DeepEquals, [][]string{
{"plymouth", "--ping"},
{"plymouth", "display-message", "--text", "Unlocked data (/dev/sda1) successfully with PIN"},
})
}
func (s *authRequestorAutoSuite) TestNotifyUserAuthResultWithExhaustedAuthTypes(c *C) {
requestor := NewAutoAuthRequestorForTesting(nil, NewPlymouthAuthRequestorForTesting(new(mockPlymouthAuthRequestorStringer), &PlymouthRequestUserCredentialContext{Name: "data", Path: "/dev/sda1"}))
c.Check(requestor.NotifyUserAuthResult(context.Background(), UserAuthResultFailed, UserAuthTypePassphrase, UserAuthTypePassphrase), IsNil)
c.Check(s.mockPlymouth.Calls(), DeepEquals, [][]string{
{"plymouth", "--ping"},
{"plymouth", "display-message", "--text", "Incorrect passphrase. No more passphrase tries remaining"},
})
}
func (s *authRequestorAutoSuite) TestNotifyUserAuthResultNoLastUsed(c *C) {
requestor := NewAutoAuthRequestorForTesting(nil, nil)
err := requestor.NotifyUserAuthResult(context.Background(), UserAuthResultSuccess, UserAuthTypePassphrase, 0)
c.Check(err, ErrorMatches, `no user credential requested yet`)
}
func (s *authRequestorAutoSuite) TestNotifyUserAuthResultCanceledContext(c *C) {
requestor := NewAutoAuthRequestorForTesting(nil, NewPlymouthAuthRequestorForTesting(new(mockPlymouthAuthRequestorStringer), &PlymouthRequestUserCredentialContext{Name: "data", Path: "/dev/sda1"}))
ctx, cancel := context.WithCancel(context.Background())
cancel()
err := requestor.NotifyUserAuthResult(ctx, UserAuthResultSuccess, UserAuthTypePassphrase, 0)
c.Check(err, ErrorMatches, `cannot execute plymouth --ping: context canceled`)
c.Check(errors.Is(err, context.Canceled), testutil.IsTrue)
}
func (s *authRequestorAutoSuite) TestNotifyUserAuthResultFail(c *C) {
requestor := NewAutoAuthRequestorForTesting(nil, NewPlymouthAuthRequestorForTesting(&mockPlymouthAuthRequestorStringer{err: errors.New("some error")}, &PlymouthRequestUserCredentialContext{Name: "data", Path: "/dev/sda1"}))
err := requestor.NotifyUserAuthResult(context.Background(), UserAuthResultSuccess, UserAuthTypePassphrase, 0)
c.Check(err, ErrorMatches, `cannot request message string: some error`)
}