Skip to content

Commit

Permalink
feat: prepared for new release (#48)
Browse files Browse the repository at this point in the history
Signed-off-by: Mohit Kumar Singh <[email protected]>
  • Loading branch information
MrUnfunny authored and hsluoyz committed Aug 20, 2021
1 parent 1a1035f commit eee526a
Show file tree
Hide file tree
Showing 58 changed files with 57 additions and 48 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.0

- All basic features are ready for use.

## 0.0.1

- Initial version
- Initial version.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: casbin
description: An authorization library that supports access control models like
ACL, RBAC, ABAC.
version: 0.0.1
version: 0.1.0
homepage: https://casbin.org/
repository: https://github.com/casbin/dart-casbin
documentation: https://casbin.org/docs/en/overview
Expand Down
59 changes: 31 additions & 28 deletions test/enforcer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import 'utils/test_utils.dart';

void main() {
group('test enable enforce with false', () {
var e = Enforcer('examples/basic_model.conf', 'examples/basic_policy.csv');
var e = Enforcer(
'casbin_examples/basic_model.conf', 'casbin_examples/basic_policy.csv');

e.enableEnforce(false);

Expand All @@ -37,7 +38,8 @@ void main() {
});

group('test enable enforce with true', () {
var e = Enforcer('examples/basic_model.conf', 'examples/basic_policy.csv');
var e = Enforcer(
'casbin_examples/basic_model.conf', 'casbin_examples/basic_policy.csv');

e.enableEnforce(true);

Expand All @@ -52,9 +54,9 @@ void main() {
});

group('test enforcer initialization with adapter', () {
var adapter = FileAdapter('examples/basic_policy.csv');
var e =
Enforcer.fromModelPathAndAdapter('examples/basic_model.conf', adapter);
var adapter = FileAdapter('casbin_examples/basic_policy.csv');
var e = Enforcer.fromModelPathAndAdapter(
'casbin_examples/basic_model.conf', adapter);

testEnforce('test 1', e, 'alice', 'data1', 'read', true);
testEnforce('test 2', e, 'alice', 'data1', 'write', false);
Expand All @@ -68,20 +70,20 @@ void main() {

group('test getModel and setModel', () {
group('before setting model', () {
var e =
Enforcer('examples/basic_model.conf', 'examples/basic_policy.csv');
var e = Enforcer('casbin_examples/basic_model.conf',
'casbin_examples/basic_policy.csv');
// var e2 = Enforcer(
// 'examples/basic_with_root_model.conf', 'examples/basic_policy.csv');
// 'casbin_examples/basic_with_root_model.conf', 'casbin_examples/basic_policy.csv');

testEnforce(
'test before setting Model', e, 'root', 'data1', 'read', false);
});

group('after setting model', () {
var e =
Enforcer('examples/basic_model.conf', 'examples/basic_policy.csv');
var e2 = Enforcer(
'examples/basic_with_root_model.conf', 'examples/basic_policy.csv');
var e = Enforcer('casbin_examples/basic_model.conf',
'casbin_examples/basic_policy.csv');
var e2 = Enforcer('casbin_examples/basic_with_root_model.conf',
'casbin_examples/basic_policy.csv');
e.setModel(e2.getModel());

testEnforce('test after setting Model', e, 'root', 'data1', 'read', true);
Expand All @@ -90,20 +92,20 @@ void main() {

group('test getAdapter and setAdapter', () {
group('before setting adapter', () {
var e =
Enforcer('examples/basic_model.conf', 'examples/basic_policy.csv');
var e = Enforcer('casbin_examples/basic_model.conf',
'casbin_examples/basic_policy.csv');
// var e2 = Enforcer(
// 'examples/basic_model.conf', 'examples/basic_inverse_policy.csv');
// 'casbin_examples/basic_model.conf', 'casbin_examples/basic_inverse_policy.csv');

testEnforce('test 1', e, 'alice', 'data1', 'read', true);
testEnforce('test 2', e, 'alice', 'data1', 'write', false);
});

group('after setting adapter', () {
var e =
Enforcer('examples/basic_model.conf', 'examples/basic_policy.csv');
var e2 = Enforcer(
'examples/basic_model.conf', 'examples/basic_inverse_policy.csv');
var e = Enforcer('casbin_examples/basic_model.conf',
'casbin_examples/basic_policy.csv');
var e2 = Enforcer('casbin_examples/basic_model.conf',
'casbin_examples/basic_inverse_policy.csv');
var a2 = e2.getAdapter();
e.setAdapter(a2);
e.loadPolicy();
Expand All @@ -114,17 +116,17 @@ void main() {
});

group('test setAdapter from file', () {
var e = Enforcer('examples/basic_model.conf');
var e = Enforcer('casbin_examples/basic_model.conf');

var a = FileAdapter('examples/basic_policy.csv');
var a = FileAdapter('casbin_examples/basic_policy.csv');
e.setAdapter(a);
e.loadPolicy();

testEnforce('test 1', e, 'alice', 'data1', 'read', true);
});

group('test enforce param validation', () {
var e = Enforcer('examples/rbac_model.conf');
var e = Enforcer('casbin_examples/rbac_model.conf');
test('must return false as there are 4 params instead of 3', () {
assert(
e.validateEnforce(['alice', 'data1', 'read', 'extra param']), false);
Expand Down Expand Up @@ -184,7 +186,7 @@ void main() {
m.addDef('m', 'm',
'r.sub == p.sub && keyMatch(r.obj, p.obj) && regexMatch(r.act, p.act)');

var a = FileAdapter('examples/keymatch_policy.csv');
var a = FileAdapter('casbin_examples/keymatch_policy.csv');

var e = Enforcer.fromModelAndAdapter(m, a);

Expand Down Expand Up @@ -219,7 +221,7 @@ void main() {
m.addDef('m', 'm',
'r.sub == p.sub && keyMatch(r.obj, p.obj) && regexMatch(r.act, p.act)');

var a = FileAdapter('examples/keymatch_policy.csv');
var a = FileAdapter('casbin_examples/keymatch_policy.csv');

var e = Enforcer.fromModelAndAdapter(m, a);

Expand All @@ -237,7 +239,7 @@ void main() {
m.addDef('m', 'm',
'r.sub == p.sub && keyMatch(r.obj, p.obj) && regexMatch(r.act, p.act)');

var a = FileAdapter('examples/keymatch_policy.csv');
var a = FileAdapter('casbin_examples/keymatch_policy.csv');

e.setModel(m);
e.setAdapter(a);
Expand Down Expand Up @@ -506,7 +508,8 @@ m = g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act
});

test('TestReloadPolicy', () {
final e = Enforcer('examples/rbac_model.conf', 'examples/rbac_policy.csv');
final e = Enforcer(
'casbin_examples/rbac_model.conf', 'casbin_examples/rbac_policy.csv');

e.loadPolicy();

Expand All @@ -522,8 +525,8 @@ m = g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act

group('test ABAC Scaling', () {
final e = Enforcer(
'examples/abac_rule_model.conf',
'examples/abac_rule_policy.csv',
'casbin_examples/abac_rule_model.conf',
'casbin_examples/abac_rule_policy.csv',
);

final sub1 = AbacTest('alice', 16);
Expand Down
8 changes: 4 additions & 4 deletions test/logger/logger_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ void main() {
});
group('test logPolicy', () {
final enf = Enforcer.fromModelPathAndPolicyFile(
'examples/basic_model.conf',
'examples/basic_policy.csv',
'casbin_examples/basic_model.conf',
'casbin_examples/basic_policy.csv',
);

testLogPolicy('test 1', logger, enf.model, 'Policy:');
Expand All @@ -80,8 +80,8 @@ void main() {

group('test logRole', () {
final enf = Enforcer.fromModelPathAndPolicyFile(
'examples/rbac_with_domains_model.conf',
'examples/rbac_with_domains_policy.csv',
'casbin_examples/rbac_with_domains_model.conf',
'casbin_examples/rbac_with_domains_policy.csv',
);
final rm = enf.rm as DefaultRoleManager;

Expand Down
3 changes: 2 additions & 1 deletion test/management_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import 'package:test/test.dart';
import 'package:casbin/src/utils/utils.dart' as utils;

void main() {
var e = Enforcer('examples/rbac_model.conf', 'examples/rbac_policy.csv');
var e = Enforcer(
'casbin_examples/rbac_model.conf', 'casbin_examples/rbac_policy.csv');

test('test getAllSubjects', () {
var allSubjects = e.getAllSubjects();
Expand Down
27 changes: 14 additions & 13 deletions test/model/model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@ import 'package:casbin/src/enforcer.dart';
import '../utils/test_utils.dart';

void main() {
final basicModelPath = 'examples/basic_model.conf';
final basicPolicyFile = 'examples/basic_policy.csv';
final rbacModelPath = 'examples/rbac_model.conf';
final rbacPolicyFile = 'examples/rbac_policy.csv';
final rbacWithResourcesModel = 'examples/rbac_with_resource_roles_model.conf';
final basicModelPath = 'casbin_examples/basic_model.conf';
final basicPolicyFile = 'casbin_examples/basic_policy.csv';
final rbacModelPath = 'casbin_examples/rbac_model.conf';
final rbacPolicyFile = 'casbin_examples/rbac_policy.csv';
final rbacWithResourcesModel =
'casbin_examples/rbac_with_resource_roles_model.conf';
final rbacWithResourcesPolicy =
'examples/rbac_with_resource_roles_policy.csv';
final rbacWithDomainsModel = 'examples/rbac_with_domains_model.conf';
final rbacWithDomainsPolicy = 'examples/rbac_with_domains_policy.csv';
final rbacWithDenyModel = 'examples/rbac_with_deny_model.conf';
final rbacWithDenyPolicy = 'examples/rbac_with_deny_policy.csv';
'casbin_examples/rbac_with_resource_roles_policy.csv';
final rbacWithDomainsModel = 'casbin_examples/rbac_with_domains_model.conf';
final rbacWithDomainsPolicy = 'casbin_examples/rbac_with_domains_policy.csv';
final rbacWithDenyModel = 'casbin_examples/rbac_with_deny_model.conf';
final rbacWithDenyPolicy = 'casbin_examples/rbac_with_deny_policy.csv';

final rbacWithNotDenyModel = 'examples/rbac_with_not_deny_model.conf';
final rbacWithNotDenyModel = 'casbin_examples/rbac_with_not_deny_model.conf';

group('Test enforcing with basic model', () {
final e =
Expand Down Expand Up @@ -101,8 +102,8 @@ void main() {

group('Test enforcing with abac model with Domains', () {
var e = Enforcer(
'examples/abac_rule_with_domains_model.conf',
'examples/abac_rule_with_domains_policy.csv',
'casbin_examples/abac_rule_with_domains_model.conf',
'casbin_examples/abac_rule_with_domains_policy.csv',
);
testDomainEnforce('test 1', e, 'alice', 'domain1', 'data1', 'read', true);
testDomainEnforce('test 2', e, 'alice', 'domain1', 'data1', 'write', true);
Expand Down

0 comments on commit eee526a

Please sign in to comment.