-
Notifications
You must be signed in to change notification settings - Fork 266
PHPLIB-1728: Encryption flag in driver metadata #1809
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
base: v2.x
Are you sure you want to change the base?
Conversation
781e640 to
130f2e6
Compare
GromNaN
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR also extracts the options array into DriverOptions in order to simplify testing the I/O of options as we do quite a bit of transformation on them.
This sounds like a good idea, and this has no impact on users, since these classes are internal and cannot be accessed from public APIs.
But I question whether an undefined and a null option have the same meaning in this context.
| public readonly Encoder $builderEncoder, | ||
| public readonly array $autoEncryption, | ||
| public readonly array $driver, | ||
| private readonly array $miscOptions, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be more specific.
Not $managerOptions because $autoEncryption is a manager option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I figured no, as if we get more specific we are tying it more to server implementation. I figured that as much as possible we want to pass options as is. In my mind it's just any options that we aren't transforming in some way.
|
|
||
| return (new self( | ||
| typeMap: $options[self::KEY_TYPE_MAP], | ||
| builderEncoder: $options[self::KEY_BUILDER_ENCODER] ?? new BuilderEncoder(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't validate that builderEncoder is an instance of BuilderEncoder before using it for a typed parameter. This will result in an unspecific TypeError.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I validate that it's an instance of Encoder in ensureValidArrayOptions. There's a test case for it too
b5c3b2d to
8b56aa2
Compare
So we can unit test options, as we're transforming some of the options that are passed stuff
Sending extra metadata in the handshake will allow us to detect when encryption is enabled. `iue` for In-Use Ecnryption was chosen to save bytes (as metadata will be truncated if it exceeds byte limit)
8b56aa2 to
ddeaac1
Compare
There were some test cases re: this in |
GromNaN
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests are failing. Do you need help for the spec tests?
| 'autoEncryption' => $this->autoEncryption, | ||
| 'driver' => $this->driver, | ||
| ] + $this->miscOptions, | ||
| fn ($option) => $option !== null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| fn ($option) => $option !== null, | |
| static fn ($option) => $option !== null, |
| return new self( | ||
| typeMap: $this->typeMap, | ||
| builderEncoder: $this->builderEncoder, | ||
| autoEncryption: $this->autoEncryption, | ||
| driver: $mergedDriver, | ||
| miscOptions: $this->miscOptions, | ||
| ); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creating a second instance of DriverOptions does not seem efficient to me, especially since this method is always called in the factory. A simple assignment is enough.
| return new self( | |
| typeMap: $this->typeMap, | |
| builderEncoder: $this->builderEncoder, | |
| autoEncryption: $this->autoEncryption, | |
| driver: $mergedDriver, | |
| miscOptions: $this->miscOptions, | |
| ); | |
| } | |
| $this->driver = $mergedDriver; | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thing is that then I'd have to change the readonly and visibility (which is fine, I can make it private I guess. Nothing is directly accessing it as of now)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you don't use CPP for $driver, you can alter its value before setting the property.
|
|
||
| public static function fromArray(array $options): self | ||
| { | ||
| $options += ['typeMap' => self::DEFAULT_TYPE_MAP]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be self::KEY_TYPE_MAP?
| $options += ['typeMap' => self::DEFAULT_TYPE_MAP]; | |
| $options += ['self::KEY_TYPE_MAP' => self::DEFAULT_TYPE_MAP]; |
Prepends
iueforIn-Use Encryptionto platform metadata string in MongoDB handshake. This will allow for easier detection of encryption usage in higher level libraries.This PR also extracts the options array into
DriverOptionsin order to simplify testing the I/O of options as we do quite a bit of transformation on them.