return m_policyCollection;
}
+ // TODO: Consider StorageBackend to be only one to alter this property
void setDefaultPolicy(const PolicyResult &defaultPolicy) {
m_defaultPolicy = defaultPolicy;
}
buckets().insert({ bucketId, newBucket });
}
+void InMemoryStorageBackend::updateBucket(const PolicyBucketId &bucketId,
+ const PolicyResult &defaultPolicy) {
+ try {
+ auto &bucket = buckets().at(bucketId);
+ bucket.setDefaultPolicy(defaultPolicy);
+ } catch (const std::out_of_range &) {
+ throw BucketNotExistsException(bucketId);
+ }
+}
+
void InMemoryStorageBackend::deleteBucket(const PolicyBucketId &bucketId) {
auto bucketErased = buckets().erase(bucketId);
if (bucketErased == 0) {
virtual PolicyBucket searchBucket(const PolicyBucketId &bucketId, const PolicyKey &key);
virtual void insertPolicy(const PolicyBucketId &bucketId, PolicyPtr policy);
virtual void createBucket(const PolicyBucketId &bucketId, const PolicyResult &defaultPolicy);
+ virtual void updateBucket(const PolicyBucketId &bucketId, const PolicyResult &defaultPolicy);
virtual void deleteBucket(const PolicyBucketId &bucketId);
virtual bool hasBucket(const PolicyBucketId &bucketId);
virtual void deletePolicy(const PolicyBucketId &bucketId, const PolicyKey &key);
virtual void insertPolicy(const PolicyBucketId &bucket, PolicyPtr policy) = 0;
virtual void createBucket(const PolicyBucketId &bucketId, const PolicyResult &defaultPolicy) = 0;
+ virtual void updateBucket(const PolicyBucketId &bucketId, const PolicyResult &defaultPolicy) = 0;
virtual void deleteBucket(const PolicyBucketId &bucketId) = 0;
virtual bool hasBucket(const PolicyBucketId &bucketId) = 0;
ASSERT_THAT(m_buckets.at(bucketId).policyCollection(), IsEmpty());
}
+TEST_F(InMemeoryStorageBackendFixture, updateBucket) {
+ using ::testing::ReturnRef;
+
+ FakeInMemoryStorageBackend backend;
+ EXPECT_CALL(backend, buckets())
+ .WillRepeatedly(ReturnRef(m_buckets));
+
+ PolicyBucketId bucketId = "bucket";
+ auto &bucket = this->createBucket(bucketId);
+ bucket.setDefaultPolicy(PredefinedPolicyType::ALLOW);
+
+ backend.updateBucket(bucketId, PredefinedPolicyType::DENY);
+
+ ASSERT_EQ(PredefinedPolicyType::DENY, bucket.defaultPolicy());
+}
+
+TEST_F(InMemeoryStorageBackendFixture, updateNonexistentBucket) {
+ using ::testing::ReturnRef;
+
+ FakeInMemoryStorageBackend backend;
+ EXPECT_CALL(backend, buckets())
+ .WillRepeatedly(ReturnRef(m_buckets));
+
+ EXPECT_THROW(backend.updateBucket("non-existent", PredefinedPolicyType::ALLOW),
+ BucketNotExistsException);
+}
TEST_F(InMemeoryStorageBackendFixture, deleteBucket) {
using ::testing::ReturnRef;
public:
MOCK_METHOD1(searchDefaultBucket, PolicyBucket(const PolicyKey &key));
MOCK_METHOD2(searchBucket, PolicyBucket(const PolicyBucketId &bucket, const PolicyKey &key));
- MOCK_METHOD2(createBucket, void(const PolicyBucketId &bucketId, const PolicyResult &defaultPolicy));
+ MOCK_METHOD2(createBucket, void(const PolicyBucketId &bucketId,
+ const PolicyResult &defaultPolicy));
+ MOCK_METHOD2(updateBucket, void(const PolicyBucketId &bucketId,
+ const PolicyResult &defaultPolicy));
MOCK_METHOD1(deleteBucket, void(const PolicyBucketId &bucketId));
MOCK_METHOD1(hasBucket, bool(const PolicyBucketId &bucketId));
MOCK_METHOD2(deletePolicy, void(const PolicyBucketId &bucketId, const PolicyKey &key));