-
Notifications
You must be signed in to change notification settings - Fork 20
✨(ARSN-538) Accept undefined prefix for ReplicationConfiguration #2571
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: development/8.2
Are you sure you want to change the base?
✨(ARSN-538) Accept undefined prefix for ReplicationConfiguration #2571
Conversation
Hello darkisdude,My role is to assist you with the merge of this Available options
Available commands
Status report is not available. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## development/8.2 #2571 +/- ##
================================================
Coverage 71.40% 71.40%
================================================
Files 221 221
Lines 17816 17817 +1
Branches 3705 3706 +1
================================================
+ Hits 12721 12723 +2
+ Misses 5091 5090 -1
Partials 4 4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| expect(rules[0].prefix).toEqual(''); | ||
| }); | ||
|
|
||
| it('should succeed for a valid configuration without a prefix', () => { |
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.
Add William as a reviewer as it's touching the db, I'm not too sure I can review confidently.
Also, is it documented on aws that replication configurations may not have a prefix anymore ? Can it impact some logic elsewhere if prefix is sometimes removed ?
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 don't think so, with Typescript I hope we are safe in Arsenal 🙏
| if (!prefix && prefix !== '') { | ||
| const prefix = rule.Prefix?.[0] ?? ''; | ||
|
|
||
| if (typeof prefix !== 'string') { |
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.
when can this happen?
rule.Prefix is types as optional string[], then we it gets a default if null/undefined : so it may only be a string....
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.
Maybe the typing is not the right one, but prefix can be an array, an object. Indeed, at this step we just parsed the XML without any validation. That's why we have this check. Does it make sense ?
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.
Indeed no need to check for the type here , can only be a string if it's not undefined/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.
@benzekrimaha are you double sure ? This is accepted with the current version:
<?xml version="1.0" encoding="UTF-8"?>
<ReplicationConfiguration
xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<Role>arn:aws:iam::003641996138:role/scality-internal/storage-manager-role</Role>
<Role>arn:aws:iam::003641996138:role/scality-internal/storage-manager-role</Role>
<Rule>
<ID>testfdg</ID>
<Prefix>
<Test>OUI</Test>
</Prefix>
<Filter>
<Prefix>fd</Prefix>
</Filter>
<Status>Enabled</Status>
<Destination>
<Bucket>arn:aws:s3:::aa-bb-2</Bucket>
</Destination>
</Rule>
</ReplicationConfiguration>
When I guess it should not. That's why we have this check (you can check new tests).
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.
Side question, with this request, would (and should) prefix be equal to String('OUI') ?
Also other side question, why is XMLRule.Prefix an array ? It doesn't make much sense, on top of that we see in the function that we are getting the first element only. What am I missing 🤔
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.
That good questions ! For the first one I tried with AWS and the request is rejected in that case, so I guess the answer is no, the request should be rejected (what I did). The second part it's how the xml parser works. In that case for example the Test will be an array of length 1 and a string OUI. Should I add one more check to make sure const prefix length is one and only one ?
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.
Test is up to you, but no need if you wanna merge now.
Ah yeah the xml parser parse everything as an array
| expect(typeof rules[0].id).toBe('string'); | ||
| expect(rules[0].prefix).toEqual(''); | ||
| }); | ||
|
|
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 have a test validating that we return malformed xml when the "prefix is invalid" (whatever it means) - or return that test if not relevant anymore (c.f. earlier comment).
the expression used to get prefix in _parsePrefix (and later malformed xml condition) is not trivial, would be better to make this plain with unit tests for _parsePrefix : which show exactly what "works" and what does not, and covers the 4 code-path (I think) in
const prefix = rule.Prefix?.[0] ?? '';
if (typeof prefix !== 'string') {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.
Make sense 🙏. I added them
| const base = { | ||
| id: '', | ||
| prefix: rule.Prefix[0], | ||
| prefix: rule.Prefix?.[0] ?? '', |
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 is duplicated with _parsePrefix, can we avoid this and do the "parsing" just once?
(though parsePrefix name is actually incorrect, it really just validates the prefix...)
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 caller of _buildRuleObject is already doing all the parsing verifications. I think it would be complicated to use _parsePrefix in this function, as it would now have to return an error.
What I would do is rename the rule parameter like this :
| prefix: rule.Prefix?.[0] ?? '', | |
| _buildRuleObject(rule: XMLRule) { | |
| _buildRuleObject(validRule: XMLRule) { |
Request integration branchesWaiting for integration branch creation to be requested by the user. To request integration branches, please comment on this pull request with the following command: Alternatively, the |
SylvainSenechal
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.
approved but review the few comments from the others
https://scality.atlassian.net/browse/ARSN-538