Skip to content

Commit

Permalink
Hide code and QR for unauthenticated GetBeam queries.
Browse files Browse the repository at this point in the history
  • Loading branch information
v16Studios committed Sep 26, 2023
1 parent e080b3b commit 38b1474
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/GraphQL/Types/BeamClaimType.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function fields(): array
'type' => GraphQL::type('String!'),
'description' => __('enjin-platform-beam::type.beam_claim.field.code'),
'resolve' => fn ($claim) => $claim->code ? $claim->singleUseCode : '',
'excludeFrom' => ['GetBeams'],
'excludeFrom' => ['GetBeam', 'GetBeams'],
],
'identifierCode' => [
'type' => GraphQL::type('String!'),
Expand All @@ -94,7 +94,7 @@ public function fields(): array
},
'selectable' => false,
'is_relation' => false,
'excludeFrom' => ['GetBeams'],
'excludeFrom' => ['GetBeam', 'GetBeams'],
],
];
}
Expand Down
16 changes: 16 additions & 0 deletions tests/Feature/GraphQL/Queries/GetBeamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Enjin\Platform\Beam\Tests\Feature\GraphQL\TestCaseGraphQL;
use Enjin\Platform\Beam\Tests\Feature\Traits\SeedBeamData;
use Enjin\Platform\Providers\Faker\SubstrateProvider;
use Illuminate\Support\Str;

class GetBeamTest extends TestCaseGraphQL
{
Expand Down Expand Up @@ -157,4 +158,19 @@ public function test_it_will_fail_with_max_character_limit(): void

$this->assertArraySubset(['code' => ['The code field must not be greater than 1024 characters.']], $response['error']);
}

public function test_it_hides_code_field_when_unauthenticated()
{
config([
'enjin-platform.auth' => 'basic_token',
'enjin-platform.auth_drivers.basic_token.token' => Str::random(),
]);

$response = $this->graphql($this->method, ['code' => $this->beam->code], true);
$this->assertEquals('Cannot query field "code" on type "BeamClaim".', $response['error']);

config([
'enjin-platform.auth' => null,
]);
}
}
7 changes: 7 additions & 0 deletions tests/Feature/GraphQL/Resources/GetBeam.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ query GetBeam($code: String!, $account: String) {
frozen
network
}
claims {
edges {
node {
code
}
}
}
claimsRemaining
}
}

0 comments on commit 38b1474

Please sign in to comment.