Skip to content
This repository has been archived by the owner on Oct 13, 2022. It is now read-only.

testでのauthJwtが何かおかしい #103

Open
Takeno-hito opened this issue Oct 5, 2020 · 3 comments
Open

testでのauthJwtが何かおかしい #103

Takeno-hito opened this issue Oct 5, 2020 · 3 comments
Labels
bug Something isn't working

Comments

@Takeno-hito
Copy link
Member

Takeno-hito commented Oct 5, 2020

public function test_test() {
        $count = 5;
        for($i = 0; $i < $count; ++$i) {
            $exh_users[] = AuthJwt::get_token($this, ['exhibition']);
            $hsh = substr($exh_users[$i]['auth_hdr']['Authorization'], 0, 15);
            echo "{$exh_users[$i]['user']->id}: {$hsh}\n";
        }
    }

を叩くと

tbrown: bearer eyJ0eXAi
cleffler: bearer eyJ0eXAi
spowlowski: bearer eyJ0eXAi
jennings18: bearer eyJ0eXAi
dereck.torp: bearer eyJ0eXAi

が返ってくる、うーん?

普通にこれは過去の議論でした、コメントん参照

@Takeno-hito Takeno-hito added the bug Something isn't working label Oct 5, 2020
@Takeno-hito
Copy link
Member Author

Takeno-hito commented Oct 5, 2020

上のやつ、過去の議論なの忘れてた

public function test_index_all() {
        $drafts = [];
        $exh = [];
        $count = 5;
        for($i = 0; $i < $count; ++$i) {
            $exh[] = factory(Exhibition::class)->create();
            $drafts[] = factory(Draft::class)->create([
                'exh_id' => $exh[$i]->id
            ]);
        }
        foreach(['blogAdmin', 'teacher'] as $key) {
            $user = AuthJwt::get_token($this, [$key]);
            $this->get('/online/drafts/', $user['auth_hdr']);
            $this->assertResponseOk();
            $this->receiveJson();
            $this->get('/online/drafts/');
            $this->assertResponseOk();
            $this->receiveJson();
            $this->assertCount($count, json_decode($this->response->getContent()));
        }
    }

これが4回分blogAdminが叩いたと判断されて通ります

@Takeno-hito
Copy link
Member Author

とりあえず actingAs() を使うことで authJwt を使わずなんならキレイに書ける事がわかったので別issueを作って作業します

@ibuki2003
Copy link
Member

調査結果:

  • AuthServiceProvider::bootはトークンごとにキャッシュされて初回しか呼ばれない
  • Controllerは毎回呼ばれている

→GETのキャッシュというよりLaravel/Lumenのテストの仕様としてそういうことになっている?

  • useridは常に同じものを認識している

→変にキャッシュがかかっているらしい

テスト段階のキャッシュっぽいので本体の影響は無いと見てよさそう。

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants