@@ -204,6 +204,28 @@ describe('Unit: Mysql extension', function () {
204
204
} ) ;
205
205
} ) ;
206
206
207
+ it ( 'uses % for user host if db host is not localhost or 127.0.0.1' , function ( ) {
208
+ const logStub = sinon . stub ( ) ;
209
+ const instance = new MysqlExtension ( { logVerbose : logStub } , { } , { } , '/some/dir' ) ;
210
+ const queryStub = sinon . stub ( instance , '_query' ) . resolves ( ) ;
211
+ queryStub . onSecondCall ( ) . resolves ( [ { password : '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19' } ] ) ;
212
+ const ctx = { } ;
213
+
214
+ return instance . createUser ( ctx , { host : '117.241.162.107' } ) . then ( ( ) => {
215
+ expect ( queryStub . calledThrice ) . to . be . true ;
216
+ expect ( queryStub . args [ 0 ] [ 0 ] ) . to . equal ( 'SET old_passwords = 0;' ) ;
217
+ expect ( queryStub . args [ 1 ] [ 0 ] ) . to . match ( / ^ S E L E C T P A S S W O R D \( ' [ a - z A - Z 0 - 9 ! @ # $ % ^ & * ( ) + _ \- = } { [ \] | : ; " / ? . > < , ` ~ ] * ' \) A S p a s s w o r d ; $ / ) ;
218
+ expect ( queryStub . args [ 2 ] [ 0 ] ) . to . match ( / ^ C R E A T E U S E R ' g h o s t - [ 0 - 9 ] { 1 , 4 } ' @ ' % ' I D E N T I F I E D W I T H m y s q l _ n a t i v e _ p a s s w o r d A S ' \* [ 0 - 9 A - F ] * ' ; $ / ) ;
219
+ expect ( logStub . calledThrice ) . to . be . true ;
220
+ expect ( logStub . args [ 0 ] [ 0 ] ) . to . match ( / d i s a b l e d o l d _ p a s s w o r d / ) ;
221
+ expect ( logStub . args [ 1 ] [ 0 ] ) . to . match ( / c r e a t e d p a s s w o r d h a s h / ) ;
222
+ expect ( logStub . args [ 2 ] [ 0 ] ) . to . match ( / s u c c e s s f u l l y c r e a t e d n e w u s e r / ) ;
223
+ expect ( ctx . mysql ) . to . exist ;
224
+ expect ( ctx . mysql . username ) . to . match ( / ^ g h o s t - [ 0 - 9 ] { 1 , 4 } $ / ) ;
225
+ expect ( ctx . mysql . password ) . to . match ( / ^ [ a - z A - Z 0 - 9 ! @ # $ % ^ & * ( ) + _ \- = } { [ \] | : ; " / ? . > < , ` ~ ] * $ / ) ;
226
+ } ) ;
227
+ } ) ;
228
+
207
229
it ( 'retries creating user if username already exists' , function ( ) {
208
230
const logStub = sinon . stub ( ) ;
209
231
const instance = new MysqlExtension ( { logVerbose : logStub } , { } , { } , '/some/dir' ) ;
@@ -288,9 +310,9 @@ describe('Unit: Mysql extension', function () {
288
310
const instance = new MysqlExtension ( { logVerbose : logStub } , { } , { } , '/some/dir' ) ;
289
311
const queryStub = sinon . stub ( instance , '_query' ) . resolves ( ) ;
290
312
291
- return instance . grantPermissions ( { mysql : { username : 'testuser' } } , { host : 'localhost' , database : 'ghost' } ) . then ( ( ) => {
313
+ return instance . grantPermissions ( { mysql : { username : 'testuser' , host : '%' } } , { host : 'localhost' , database : 'ghost' } ) . then ( ( ) => {
292
314
expect ( queryStub . calledTwice ) . to . be . true ;
293
- expect ( queryStub . calledWithExactly ( 'GRANT ALL PRIVILEGES ON ghost.* TO \'testuser\'@\'localhost \';' ) ) . to . be . true ;
315
+ expect ( queryStub . calledWithExactly ( 'GRANT ALL PRIVILEGES ON ghost.* TO \'testuser\'@\'% \';' ) ) . to . be . true ;
294
316
expect ( queryStub . calledWithExactly ( 'FLUSH PRIVILEGES;' ) ) . to . be . true ;
295
317
expect ( logStub . calledTwice ) . to . be . true ;
296
318
expect ( logStub . args [ 0 ] [ 0 ] ) . to . match ( / S u c c e s s f u l l y g r a n t e d p r i v i l e g e s / ) ;
0 commit comments