Luamnoxu's avatar

php artisan test errors with "The MAC is invalid."

Right now I am using a docker-image with Laravel to locally test a few things.

Weirdly enough any test that involves Users errors out with the error "The MAC is invalid." Ive tried regenerating the APP_KEY and clearing all the volumes and images however no luck. Googling around doesnt seem to be of any help either as all the mentions i can find of The MAC is invalid. are outside of testing.

Other tests run fine and accessing the things meant to be tested seems to work fine aswell. For context the test mentioned in the logs looks like this:

    public function test_Can_read_Email()
    {
        $user = User::factory()->create(['isAdmin' => 1]);

        $project = Project::factory()->hasEmails(1)->create();

        // Attach the project to the user with a specific role in the pivot table
        $user->project()->attach($project, ['role' => 2]);

        $user->load('project');

        $project = $user->project()->first();
        $projectId = $project->id;
        dump($projectId);

        $this->actingAs($user);
        $response = $this->get("/mail/project/{$projectId}/settings");
        $response->assertOk();

        $this->assertDatabaseCount(Project::class, 2);
    }

If it is of any help, these tests run fine on the Production server.

0 likes
2 replies
vincent15000's avatar

Often this error is related to encryption / decryption.

I don't see any encryption / decryption in your test.

Some curiosity : your test is named test_can_read_email, but I don't see anything in your test code related that could assert that an email has been read.

Please or to participate in this conversation.