lukeraymonddowning / honey

A spam prevention package for Laravel, providing honeypot techniques, ip blocking and beautifully simple Recaptcha integration. Stop spam. Use Honey.
MIT License
398 stars 23 forks source link

spammerIpTracking running even if Honey::disable() is called #47

Open jbajou opened 2 years ago

jbajou commented 2 years ago

Hello,

I'm trying to deactivate any action from this package in my tests (as it doesn't make sense + I don't have to setup spammers table, etc).

My problem is that it still tries to access the spammers table even if I call Honey::disable();.

My honey.environments is as follow:

'environments' => [
        'production',
    ],

Any idea how I could disable all actions from the package to run my tests ?

Thank you!

jbajou commented 2 years ago

hello! I checked a bit the code and it doesn't look like this feature can be disabled by the environments key and that the only way to not run is to remove it from the features key.

Can anyone confirm ?

lukeraymonddowning commented 2 years ago

Hey @jbajou,

can you post your findings here?

jbajou commented 2 years ago

hey @lukeraymonddowning. Sorry for not getting back here sooner.

Turned out I need to disabled Honey as follow:

public function setupUp() : void 
{
        parent::setUp();
        config(['honey.features' => []]);
        Honey::disable();
        // More cool stuff here
}

If I don't explicitly reset honey.features, the spammers test is still done. I can't remember much about it, but I think it's linked to the test being done in the constructor https://github.com/lukeraymonddowning/honey/blob/7fbc6bdc023f499ea61c9e4ae80d40396bcf6b70/src/Honey.php#L28

Hope that helps