用于测试API Jetstream Sanctum Laravel 8x的HEADER的问题,带权限

时间:2020-10-08 21:04:13

标签: laravel api header laravel-sanctum

我生成了两个令牌:

tokenA = As2 ... xxxxx //can perform ONLY  create
tokenB = Bs2 ... xxxxx //can perform ONLY update

我有以下问题

$response = $this->withHeaders([
            'Accept' => 'application/json',
            'Authorization' => 'Bearer '.$tokenA],
        ])->post('/api/store',$data);
        $response->assertStatus(201);

//the store is made without problems

$response = $this->withHeaders([
            'Accept' => 'application/json',
            'Authorization' => 'Bearer '.tokenB,
        ])->put('/api/update',$dataUpdate);
        $respone->assertStatus(200);

//the test fails and returns 403. As if you don't have permission to do that

如果我只打一个电话

$response = $this->withHeaders([
            'Accept' => 'application/json',
            'Authorization' => 'Bearer '.tokenB,
        ])->put('/api/update',$dataUpdate);
        $response->assertStatus(200);

执行更新没有问题。

如何依次运行商店和更新?

似乎$ response继续持有tokenA的值

0 个答案:

没有答案