11
11
12
12
namespace Tymon \JWTAuth \Test \Providers \JWT ;
13
13
14
+ use Illuminate \Support \Str ;
14
15
use Tymon \JWTAuth \Exceptions \JWTException ;
15
16
use Tymon \JWTAuth \Exceptions \TokenInvalidException ;
16
17
use Tymon \JWTAuth \Providers \JWT \Lcobucci ;
@@ -30,7 +31,7 @@ public function it_can_encode_claims_using_a_symmetric_key()
30
31
'custom_claim ' => 'foobar ' ,
31
32
];
32
33
33
- $ token = $ this ->getProvider (' secret ' , Provider::ALGO_HS256 )->encode ($ payload );
34
+ $ token = $ this ->getProvider (Str:: random ( 64 ) , Provider::ALGO_HS256 )->encode ($ payload );
34
35
[$ header , $ payload , $ signature ] = explode ('. ' , $ token );
35
36
36
37
$ claims = json_decode (base64_decode ($ payload ), true );
@@ -57,7 +58,7 @@ public function it_can_encode_and_decode_a_token_using_a_symmetric_key()
57
58
'custom_claim ' => 'foobar ' ,
58
59
];
59
60
60
- $ provider = $ this ->getProvider (' secret ' , Provider::ALGO_HS256 );
61
+ $ provider = $ this ->getProvider (Str:: random ( 64 ) , Provider::ALGO_HS256 );
61
62
62
63
$ token = $ provider ->encode ($ payload );
63
64
$ claims = $ provider ->decode ($ token );
@@ -81,7 +82,7 @@ public function it_can_encode_and_decode_a_token_using_an_asymmetric_RS256_key()
81
82
];
82
83
83
84
$ provider = $ this ->getProvider (
84
- ' secret ' ,
85
+ Str:: random ( 64 ) ,
85
86
Provider::ALGO_RS256 ,
86
87
['private ' => $ this ->getDummyPrivateKey (), 'public ' => $ this ->getDummyPublicKey ()]
87
88
);
@@ -115,7 +116,7 @@ public function it_should_throw_an_invalid_exception_when_the_payload_could_not_
115
116
'invalid_utf8 ' => "\xB1\x31" , // cannot be encoded as JSON
116
117
];
117
118
118
- $ this ->getProvider (' secret ' , Provider::ALGO_HS256 )->encode ($ payload );
119
+ $ this ->getProvider (Str:: random ( 64 ) , Provider::ALGO_HS256 )->encode ($ payload );
119
120
}
120
121
121
122
/** @test */
@@ -125,8 +126,8 @@ public function it_should_throw_a_token_invalid_exception_when_the_token_could_n
125
126
$ this ->expectExceptionMessage ('Token Signature could not be verified. ' );
126
127
127
128
// This has a different secret than the one used to encode the token
128
- $ this ->getProvider (' secret ' , Provider::ALGO_HS256 )
129
- ->decode ('eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIiwiZXhwIjoxNjQ5MjYxMDY1LCJpYXQiOjE2NDkyNTc0NjUsImlzcyI6Ii9mb28iLCJjdXN0b21fY2xhaW0iOiJmb29iYXIifQ.jZufNqDHAxtboUIPmDp4ZFOIQxK-B5G6vNdBEp-9uL8 ' );
129
+ $ this ->getProvider (Str:: random ( 64 ) , Provider::ALGO_HS256 )
130
+ ->decode ('eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIiwiZXhwIjoxNjQ5MjYxMDY1LCJpYXQiOjE2NDkyNTc0NjUsImlzcyI6Ii9mb28iLCJjdXN0b21fY2xhaW0iOiJmb29iYXIifQ.jamiInQiin-1RUviliPjZxl0MLEnQnVTbr2sGooeXBY ' );
130
131
}
131
132
132
133
/** @test */
@@ -136,8 +137,8 @@ public function it_should_throw_a_token_invalid_exception_when_the_token_could_n
136
137
$ this ->expectExceptionMessage ('Token Signature could not be verified. ' );
137
138
138
139
// This sub claim for this token has been tampered with so the signature will not match
139
- $ this ->getProvider (' secret ' , Provider::ALGO_HS256 )
140
- ->decode ('eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIyIiwiZXhwIjoxNjQ5MjY0OTA2LCJpYXQiOjE2NDkyNjEzMDYsImlzcyI6Ii9mb28iLCJjdXN0b21fY2xhaW0iOiJmb29iYXIifQ.IcJvMvwMXf8oEpnz8-hvAy60QDE_o8XFaxhbZIGVy0U ' );
140
+ $ this ->getProvider (Str:: random ( 64 ) , Provider::ALGO_HS256 )
141
+ ->decode ('eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIiwiZXhwIjoxNjQ5MjYxMDY1LCJpYXQiOjE2NDkyNTc0NjUsImlzcyI6Ii9mb29iYXIiLCJjdXN0b21fY2xhaW0iOiJmb29iYXIifQ.jamiInQiin-1RUviliPjZxl0MLEnQnVTbr2sGooeXBY ' );
141
142
}
142
143
143
144
/** @test */
0 commit comments