MojErr MojDbRevTest::checkRevEq(MojDb& db, const MojObject& id, const MojObject& rev) { MojObject obj; bool found = false; MojErr err = db.get(id, obj, found); MojTestErrCheck(err); MojTestAssert(found); MojObject rev2; err = obj.getRequired(MojDb::RevKey, rev2); MojTestErrCheck(err); MojTestAssert(rev == rev2); return MojErrNone; }
MojErr MojDbPermissionTest::checkPermissions(MojDb& db) { MojDbReq reqOwner(false); MojErr err = reqOwner.domain(_T("com.foo")); MojTestErrCheck(err); MojDbReq reqFooBar(false); err = reqFooBar.domain(_T("com.foo.bar")); MojTestErrCheck(err); MojDbReq reqFooBarBad(false); err = reqFooBarBad.domain(_T("com.foobar")); MojTestErrCheck(err); MojDbReq reqGranted(false); err = reqGranted.domain("com.granted"); MojTestErrCheck(err); MojDbReq reqEmpty(false); MojDbReq reqBad(false); err = reqBad.domain("com.bad"); MojTestErrCheck(err); MojObject objNoId; err = objNoId.putString(MojDb::KindKey, _T("PermissionTest:1")); MojTestErrCheck(err); MojObject obj2NoId; err = obj2NoId.putString(MojDb::KindKey, _T("PermissionTest2:1")); MojTestErrCheck(err); // put new obj MojObject obj1 = objNoId; err = db.put(obj1, MojDb::FlagNone, reqOwner); MojTestErrCheck(err); MojObject obj2 = objNoId; err = db.put(obj2, MojDb::FlagNone, reqGranted); MojTestErrCheck(err); MojObject obj3 = objNoId; err = db.put(obj3, MojDb::FlagNone, reqBad); MojTestErrExpected(err, MojErrDbPermissionDenied); obj3 = objNoId; err = db.put(obj3, MojDb::FlagNone, reqFooBarBad); MojTestErrExpected(err, MojErrDbPermissionDenied); obj3 = objNoId; err = db.put(obj3, MojDb::FlagNone, reqFooBar); MojTestErrCheck(err); err = db.put(obj2NoId, MojDb::FlagNone, reqEmpty); MojTestErrCheck(err); // put existing obj err = obj1.put(_T("foo"), 1); MojTestErrCheck(err); err = db.put(obj1, MojDb::FlagNone, reqOwner); MojTestErrCheck(err); err = obj2.put(_T("foo"), 2); MojTestErrCheck(err); err = db.put(obj2, MojDb::FlagNone, reqGranted); MojTestErrCheck(err); err = obj2.put(_T("foo"), 3); MojTestErrCheck(err); err = db.put(obj2, MojDb::FlagNone, reqBad); MojTestErrExpected(err, MojErrDbPermissionDenied); // find MojDbQuery query; err = query.from(_T("PermissionTest:1")); MojTestErrCheck(err); MojDbCursor cursor; err = db.find(query, cursor, reqOwner); MojTestErrCheck(err); err = cursor.close(); MojTestErrCheck(err); err = db.find(query, cursor, reqGranted); MojTestErrCheck(err); err = cursor.close(); MojTestErrCheck(err); err = db.find(query, cursor, reqBad); MojTestErrExpected(err, MojErrDbPermissionDenied); err = cursor.close(); MojTestErrCheck(err); // get MojObject id1; MojTestAssert(obj1.get(MojDb::IdKey, id1)); bool found = false; MojObject gotten; err = db.get(id1, gotten, found, reqOwner); MojTestErrCheck(err); err = db.get(id1, gotten, found, reqGranted); MojTestErrCheck(err); err = db.get(id1, gotten, found, reqBad); MojTestErrExpected(err, MojErrDbPermissionDenied); // del by id err = db.del(id1, found, MojDb::FlagNone, reqBad); MojTestErrExpected(err, MojErrDbPermissionDenied); MojTestAssert(!found); err = db.del(id1, found, MojDb::FlagNone, reqOwner); MojTestErrCheck(err); MojTestAssert(found); MojObject id2; MojTestAssert(obj2.get(MojDb::IdKey, id2)); err = db.del(id2, found, MojDb::FlagNone, reqGranted); MojTestErrCheck(err); MojTestAssert(found); // del query MojUInt32 count = 0; err = db.del(query, count, MojDb::FlagNone, reqOwner); MojTestErrCheck(err); err = db.del(query, count, MojDb::FlagNone, reqGranted); MojTestErrCheck(err); err = db.del(query, count, MojDb::FlagNone, reqBad); MojTestErrExpected(err, MojErrDbPermissionDenied); return MojErrNone; }