File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed
src/Infrastructure/Ci/System/Github/Credentials
tests/Unit/Infrastructure/Ci/System/Github/Credentials Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change 8
8
use ArtARTs36 \MergeRequestLinter \Infrastructure \Contracts \CI \InvalidCredentialsException ;
9
9
use ArtARTs36 \MergeRequestLinter \Infrastructure \Contracts \Configuration \ConfigValueTransformer ;
10
10
use ArtARTs36 \MergeRequestLinter \Infrastructure \Contracts \Configuration \TransformConfigValueException ;
11
+ use ArtARTs36 \Str \Facade \Str ;
11
12
12
13
class GithubActionsCredentialsMapper implements AuthenticatorMapper
13
14
{
@@ -28,7 +29,13 @@ public function map(array $credentials): Authenticator
28
29
}
29
30
30
31
try {
31
- return HeaderAuthenticator::bearer ($ this ->value ->tryTransform ($ credentials ['token ' ]));
32
+ $ token = $ this ->value ->tryTransform ($ credentials ['token ' ]);
33
+
34
+ if (Str::isEmpty ($ token )) {
35
+ throw new InvalidCredentialsException ('Failed to resolve github token: token is empty ' );
36
+ }
37
+
38
+ return HeaderAuthenticator::bearer ($ token );
32
39
} catch (TransformConfigValueException $ e ) {
33
40
throw new InvalidCredentialsException (sprintf (
34
41
'Failed to resolve github token: %s ' ,
Original file line number Diff line number Diff line change 6
6
use ArtARTs36 \MergeRequestLinter \Infrastructure \Ci \System \Github \Credentials \GithubActionsCredentialsMapper ;
7
7
use ArtARTs36 \MergeRequestLinter \Infrastructure \Configuration \Value \CompositeTransformer ;
8
8
use ArtARTs36 \MergeRequestLinter \Infrastructure \Contracts \CI \InvalidCredentialsException ;
9
+ use ArtARTs36 \MergeRequestLinter \Infrastructure \Contracts \Configuration \ConfigValueTransformer ;
9
10
use ArtARTs36 \MergeRequestLinter \Tests \TestCase ;
11
+ use PHPUnit \Framework \MockObject \Rule \InvokedCount ;
10
12
11
13
final class GithubActionsCredentialsMapperTest extends TestCase
12
14
{
@@ -35,4 +37,25 @@ public function testMapOnInvalidCredentials(): void
35
37
36
38
$ mapper ->map ([]);
37
39
}
40
+
41
+ /**
42
+ * @covers \ArtARTs36\MergeRequestLinter\Infrastructure\Ci\System\Github\Credentials\GithubActionsCredentialsMapper::map
43
+ * @covers \ArtARTs36\MergeRequestLinter\Infrastructure\Ci\System\Github\Credentials\GithubActionsCredentialsMapper::__construct
44
+ */
45
+ public function testMapOnTransformReturnsEmptyValue (): void
46
+ {
47
+ $ transformer = $ this ->createMock (ConfigValueTransformer::class);
48
+ $ transformer
49
+ ->expects (new InvokedCount (1 ))
50
+ ->method ('tryTransform ' )
51
+ ->willReturn ('' );
52
+
53
+ $ mapper = new GithubActionsCredentialsMapper ($ transformer );
54
+
55
+ self ::expectExceptionMessage ('Failed to resolve github token: token is empty ' );
56
+
57
+ $ mapper ->map ([
58
+ 'token ' => '${} ' ,
59
+ ]);
60
+ }
38
61
}
You can’t perform that action at this time.
0 commit comments