Repository navigation
Conversation
|
Closing this PR, Added #9087 to v5 milestone so this and other related scope issues will also be a focus of v5 release |
|
@sushantdhiman What was wrong with the PR? I think it solved the issue pretty simply. |
|
Hmm, ok lets merge this as it solves scoped attributes issue at least. We can fix scopes later on |
| }); | ||
| }); | ||
|
|
||
| it('should be applied before query options for attributes exclude', function() { |
There was a problem hiding this comment.
Its worth adding a test for case when scope is trying to exclude some attribute but actual call is trying to include it. Which again comes to a discussion matter, I think scope should still exclude that attribute
There was a problem hiding this comment.
@sushantdhiman The test below this one does that (should be applied before query options for attributes include)
There was a problem hiding this comment.
lowAccess is only setting attributes to ['other_value', 'access_level'],, its not excluding email, so shouldn't include at method level should be able to inject email to attributes?
I think it would make sense if scope say exclude something then finder method should not be allowed to include that attribute, if scopes are just specifying attributes or using include, then finder method should be able to expand that list of attributes
There was a problem hiding this comment.
@sushantdhiman I think I see what you're asking for, I'll add that test but it does function like that in both cases - includes only applies to the sum output of the previous scope, so in both cases you can't include an attribute if the scope had it in exclude or it wasn't in attributes.
|
@sushantdhiman Any update on this? |
|
Hello @contra, thank you again for taking a look in my issue. Unfortunately, this PR does not solve it. Looks like you're fixing something else with this PR though, so that's great :) Please just remove the "closes 9087" thing from the PR / commit, since it actually does not close it at all... If you disagree and/or would like further clarifications, let me know. |
|
@contra Sure. The very first comment of the issue itself, for example, still behaves exactly as I posted. Converting my post to a test is fairly straightforward: beforeEach(function() {
this.Foo = this.sequelize.define('foo', { name: Sequelize.STRING }, { timestamps: false });
this.Bar = this.sequelize.define('bar', { name: Sequelize.STRING }, { timestamps: false });
this.Foo.hasMany(this.Bar, { foreignKey: 'fooId' });
this.Foo.addScope('testScope', {
include: [{
model: this.Bar,
where: {
name: 'bar1'
}
}]
});
});
it('should merge scope with findAll options correctly', function() {
const self = this;
return this.sequelize.sync({ force: true })
.then(() => self.Foo.create({ name: 'foo1' }))
.then(foo1 => this.Bar.create({ name: 'bar1', fooId: foo1.id }))
.then(() => self.Foo.create({ name: 'foo2' }))
.then(foo2 => this.Bar.create({ name: 'bar2', fooId: foo2.id }))
.then(() => self.Foo.scope('testScope').findAll({
include: [{
model: this.Bar,
attributes: { exclude: ['name'] }
}]
}))
.then(result => {
result = result.map(x => x.toJSON());
expect(result).to.deep.equal([
{
'id': 1,
'name': 'foo1',
'bars': [
{
'id': 1,
'fooId': 1
}
]
}
]);
});
});Also, my other comment with extra examples is also not covered so far. There I show three situations, which I call situations A, B and C, that should all have the same output (the output from A) but currently have different outputs. Another great test to be included would be a test checking those exact three situations for the same output (the one from A). It would be great if you could add those tests to your PR and make them pass! Thank you very much once more for taking the time. If you need further clarifications, let me know. |
|
@papb Thanks for those - will add those and work on getting them to pass when I have a spare minute. |
|
Fixed by #9087 |
Pull Request check-list
Please make sure to review and check all of these items:
npm run testornpm run test-DIALECTpass with this change (including linting)?Description of change
Information: #9087 (comment)
I would recommend backporting this to v4 as well since this is a security issue. This would be hard/impossible to exploit in a targeted way so I don't think it deserves a CVE or private disclosure, but this could be a bad leak of sensitive fields for some people.