Exemplo n.º 1
0
TEST(storage, updatePolicies) {
    using ::testing::Return;
    FakeStorageBackend backend;
    Cynara::Storage storage(backend);

    PolicyBucketId testBucket1 = "test-bucket-1";
    PolicyBucketId testBucket2 = "test-bucket-2";

    std::vector<Storage::PolicyPolicyBucket> policiesToInsert = {
        std::make_tuple(Policy::simpleWithKey(Helpers::generatePolicyKey("1"), PredefinedPolicyType::ALLOW), testBucket1),
        std::make_tuple(Policy::simpleWithKey(Helpers::generatePolicyKey("2"), PredefinedPolicyType::DENY), testBucket1),
        std::make_tuple(Policy::simpleWithKey(Helpers::generatePolicyKey("3"), PredefinedPolicyType::DENY), testBucket1),
        std::make_tuple(Policy::simpleWithKey(Helpers::generatePolicyKey("4"), PredefinedPolicyType::ALLOW), testBucket2),
        std::make_tuple(Policy::simpleWithKey(Helpers::generatePolicyKey("5"), PredefinedPolicyType::ALLOW), testBucket2),
    };


    PolicyCollection pc({std::get<0>(policiesToInsert.at(0))});

    for (const auto &policy : policiesToInsert) {
        PolicyBucketId bucketId;
        PolicyPtr policyPtr;
        std::tie(policyPtr, bucketId) = policy;
        EXPECT_CALL(backend, searchBucket(bucketId, policyPtr->key()))
            .WillOnce(Return(PolicyBucket(PolicyCollection({std::get<0>(policy)}))));
        EXPECT_CALL(backend, deletePolicy(bucketId, policyPtr->key()));
        EXPECT_CALL(backend, insertPolicy(bucketId, policyPtr));
    }

    storage.insertPolicies(policiesToInsert);
}
Exemplo n.º 2
0
void PolicyBucket::insertPolicy(PolicyPtr policy) {
    const auto gluedKey = PolicyKeyHelpers::glueKey(policy->key());
    m_policyCollection[gluedKey] = policy;
}