示例#1
0
MojErr MojDbPermissionTest::testAdminPermissions(MojDb& db)
{
	MojObject permission;
	MojErr err = permission.fromJson(MojTestAdminPermission1);
	MojTestErrCheck(err);

	err = db.putPermissions(&permission, &permission + 1);
	MojTestErrCheck(err);

	MojDbReq reqAdmin(false);
	err = reqAdmin.domain(_T("com.admin"));
	MojTestErrCheck(err);

	// put kind with non-matching owner with admin role
	MojObject kind;
	err = kind.fromJson(MojTestKind1);
	MojTestErrCheck(err);
	err = db.putKind(kind, MojDb::FlagNone, reqAdmin);
	MojTestErrCheck(err);
	err = kind.fromJson(MojTestKind2);
	MojTestErrCheck(err);
	err = db.putKind(kind, MojDb::FlagNone, reqAdmin);
	MojTestErrCheck(err);

	return MojErrNone;
}
示例#2
0
MojErr MojDbPermissionTest::checkInvalid(const MojChar* json, MojDb& db)
{
	MojObject permission;
	MojErr err = permission.fromJson(json);
	MojTestErrCheck(err);
	err = db.putPermissions(&permission, &permission+1);
	MojTestErrExpected(err, MojErrDbInvalidCaller);

	return MojErrNone;
}
示例#3
0
MojErr MojDbPermissionTest::putPermissions(MojDb& db)
{
	MojDbReq reqOwner(false);
	MojErr err = reqOwner.domain(_T("com.foo"));
	MojTestErrCheck(err);
	MojDbReq reqGranted(false);
	err = reqGranted.domain("com.granted 3287");
	MojTestErrCheck(err);
	MojDbReq reqBad(false);
	err = reqBad.domain("com.bad");
	MojTestErrCheck(err);

	MojObject permission;
	err = permission.fromJson(MojTestPermission1);
	MojTestErrCheck(err);
	err = db.putPermissions(&permission, &permission + 1, reqBad);
	MojTestErrExpected(err, MojErrDbPermissionDenied);
	err = reqBad.abort();
	MojTestErrCheck(err);
	err = db.putPermissions(&permission, &permission + 1, reqOwner);
	MojTestErrCheck(err);
	err = db.putPermissions(&permission, &permission + 1, reqGranted);
	MojTestErrExpected(err, MojErrDbPermissionDenied);
	err = reqGranted.abort();
	MojTestErrCheck(err);

	err = permission.fromJson(MojTestPermissionWildcard);
	MojTestErrCheck(err);
	err = db.putPermissions(&permission, &permission + 1, reqOwner);
	MojTestErrCheck(err);
	err = permission.fromJson(MojTestPermissionWildcard2);
	MojTestErrCheck(err);
	err = db.putPermissions(&permission, &permission + 1, reqOwner);
	MojTestErrCheck(err);

	return MojErrNone;
}