Skip to content

Commit 15be3c3

Browse files
committed
test(encryption): assert that views are prohibited with encryption
1 parent cb78e69 commit 15be3c3

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

test/functional/client_side_encryption_prose_tests.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,5 +682,75 @@ describe(
682682
});
683683
}
684684
});
685+
686+
describe('Views are prohibited', function() {
687+
before(function() {
688+
// First, perform the setup.
689+
690+
// #. Create a MongoClient without encryption enabled (referred to as ``client``).
691+
this.client = this.configuration.newClient(
692+
{},
693+
{ useNewUrlParser: true, useUnifiedTopology: true }
694+
);
695+
696+
return this.client
697+
.connect()
698+
.then(() => {
699+
return this.client
700+
.db(dataDbName)
701+
.dropCollection(dataCollName)
702+
.catch(noop);
703+
})
704+
.then(() => {
705+
return this.client.db(dataDbName).createCollection(dataCollName);
706+
})
707+
.then(() => {
708+
return this.client
709+
.db(dataDbName)
710+
.createCollection('view', { viewOn: dataCollName, pipeline: [] });
711+
});
712+
});
713+
714+
after(function() {
715+
return this.client && this.client.close();
716+
});
717+
718+
beforeEach(function() {
719+
this.clientEncrypted = this.configuration.newClient(
720+
{},
721+
{
722+
useNewUrlParser: true,
723+
useUnifiedTopology: true,
724+
autoEncryption: {
725+
keyVaultNamespace,
726+
kmsProviders
727+
}
728+
}
729+
);
730+
731+
return this.clientEncrypted.connect();
732+
});
733+
734+
afterEach(function() {
735+
return this.clientEncrypted && this.clientEncrypted.close();
736+
});
737+
738+
it('should error when inserting into a view with autoEncryption', function() {
739+
this.clientEncrypted
740+
.db(dataDbName)
741+
.collection('view')
742+
.insertOne({ a: 1 })
743+
.then(
744+
() => {
745+
throw new Error('Expected insert to fail, but it succeeded');
746+
},
747+
err => {
748+
expect(err)
749+
.to.have.property('message')
750+
.that.matches(/cannot auto encrypt a view/);
751+
}
752+
);
753+
});
754+
});
685755
}
686756
);

0 commit comments

Comments
 (0)