-
Notifications
You must be signed in to change notification settings - Fork 3
fix(queue): authenticate Redis connections when credentials are configured #260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
96df801
fix(queue): authenticate Redis connections when credentials are confi…
ChiragAgg5k 91af3ca
chore(queue): merge main into fix/queue-redis-auth
ChiragAgg5k 3087b44
test(queue): assert auth rejection by its side effect and cover clust…
ChiragAgg5k 6d5bbdd
test(queue): assert auth rejection by its side effect, not Redis wording
ChiragAgg5k File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Tests\E2E\Adapter; | ||
|
|
||
| use PHPUnit\Framework\TestCase; | ||
| use Utopia\Queue\Connection\Redis; | ||
|
|
||
| /** | ||
| * Runs against the `redis-auth` compose service: `requirepass secretpw` for the | ||
| * default user and an ACL user `worker` with password `workerpw`. | ||
| */ | ||
| final class RedisAuthTest extends TestCase | ||
| { | ||
| private const string HOST = '127.0.0.1'; | ||
| private const int PORT = 16380; | ||
| private const string PASSWORD = 'secretpw'; | ||
| private const string USER = 'worker'; | ||
| private const string USER_PASSWORD = 'workerpw'; | ||
|
|
||
| public function testPasswordAuthenticatesDefaultUser(): void | ||
| { | ||
| $this->assertRoundTrip(new Redis(self::HOST, self::PORT, null, self::PASSWORD)); | ||
| } | ||
|
|
||
| public function testUserAndPasswordAuthenticateAclUser(): void | ||
| { | ||
| $this->assertRoundTrip(new Redis(self::HOST, self::PORT, self::USER, self::USER_PASSWORD)); | ||
| } | ||
|
|
||
| public function testMissingCredentialsAreRejected(): void | ||
| { | ||
| $this->assertRejected(new Redis(self::HOST, self::PORT)); | ||
| } | ||
|
|
||
| public function testWrongPasswordIsRejected(): void | ||
| { | ||
| $this->assertRejected(new Redis(self::HOST, self::PORT, self::USER, 'not-the-password')); | ||
| } | ||
|
|
||
| /** | ||
| * A credentialed connection can write a job and read it back. | ||
| */ | ||
| private function assertRoundTrip(Redis $connection): void | ||
| { | ||
| $key = 'auth-test-' . uniqid(); | ||
|
|
||
| $this->assertTrue($connection->rightPush($key, 'payload')); | ||
| $this->assertSame('payload', $connection->rightPop($key, 1)); | ||
| } | ||
|
|
||
| /** | ||
| * The observable contract of rejected credentials: the push throws, and the | ||
| * server holds nothing for that key when a trusted connection looks. | ||
| */ | ||
| private function assertRejected(Redis $rejected): void | ||
| { | ||
| $key = 'auth-test-' . uniqid(); | ||
| $thrown = null; | ||
|
|
||
| try { | ||
| $rejected->rightPush($key, 'payload'); | ||
| } catch (\RedisException $e) { | ||
| $thrown = $e; | ||
| } | ||
|
|
||
| $trusted = new Redis(self::HOST, self::PORT, null, self::PASSWORD); | ||
|
|
||
| $this->assertInstanceOf(\RedisException::class, $thrown, 'Push with rejected credentials must throw'); | ||
| $this->assertSame(0, $trusted->listSize($key), 'Rejected push must not reach the server'); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.