Skip to content

Commit

Permalink
Merge pull request #18 from hackerchai/master
Browse files Browse the repository at this point in the history
Feat: bump version 0.4.1
  • Loading branch information
hackerchai authored Aug 31, 2020
2 parents 781b54f + bb13c03 commit e7481b0
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "actix-casbin-auth"
version = "0.4.0"
version = "0.4.1"
authors = ["Eason Chai <[email protected]>","Cheng JIANG <[email protected]>"]
edition = "2018"
license = "Apache-2.0"
Expand Down
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Add it to `Cargo.toml`

```rust
actix-casbin-auth = "0.4.0"
actix-casbin-auth = "0.4.1"
actix-rt = "1.1.1"
actix-web = "2.0.0"
```
Expand Down Expand Up @@ -107,11 +107,21 @@ mod fake_auth;

#[actix_rt::main]
async fn main() -> Result<()> {
let m = DefaultModel::from_file("examples/rbac_restful_keymatch2_model.conf").await?;
let a = FileAdapter::new("examples/rbac_restful_keymatch2_policy.csv"); //You can also use diesel-adapter or sqlx-adapter
let m = DefaultModel::from_file("examples/rbac_with_pattern_model.conf")
.await
.unwrap();
let a = FileAdapter::new("examples/rbac_with_pattern_policy.csv"); //You can also use diesel-adapter or sqlx-adapter

let casbin_middleware = CasbinService::new(m, a).await;

casbin_middleware
.write()
.await
.get_role_manager()
.write()
.unwrap()
.matching_fn(Some(key_match2), None);

HttpServer::new(move || {
App::new()
.wrap(casbin_middleware.clone())
Expand Down
14 changes: 0 additions & 14 deletions examples/rbac_restful_keymatch2_model.conf

This file was deleted.

2 changes: 0 additions & 2 deletions examples/rbac_restful_keymatch2_policy.csv

This file was deleted.

3 changes: 1 addition & 2 deletions examples/rbac_with_domains_model.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ p = sub, dom, obj, act

[role_definition]
g = _, _, _
g2 = _, _, _

[policy_effect]
e = some(where (p.eft == allow))

[matchers]
m = g(r.sub, p.sub, r.dom) && r.dom == p.dom && r.obj == p.obj && r.act == p.act
m = g(r.sub, p.sub, r.dom) && r.dom == p.dom && r.obj == p.obj && regexMatch(r.act, p.act)
15 changes: 12 additions & 3 deletions tests/test_middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use futures::future::{ok, Future, Ready};
use actix_casbin_auth::{CasbinService, CasbinVals};

use actix_web::{test, web, App};
use casbin::{DefaultModel, FileAdapter};
use casbin::function_map::key_match2;
use casbin::{CoreApi, DefaultModel, FileAdapter};

pub struct FakeAuth;

Expand Down Expand Up @@ -69,13 +70,21 @@ where

#[actix_rt::test]
async fn test_middleware() {
let m = DefaultModel::from_file("examples/rbac_restful_keymatch2_model.conf")
let m = DefaultModel::from_file("examples/rbac_with_pattern_model.conf")
.await
.unwrap();
let a = FileAdapter::new("examples/rbac_restful_keymatch2_policy.csv");
let a = FileAdapter::new("examples/rbac_with_pattern_policy.csv");

let casbin_middleware = CasbinService::new(m, a).await;

casbin_middleware
.write()
.await
.get_role_manager()
.write()
.unwrap()
.matching_fn(Some(key_match2), None);

let mut app = test::init_service(
App::new()
.wrap(casbin_middleware.clone())
Expand Down
15 changes: 12 additions & 3 deletions tests/test_set_enforcer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use futures::future::{ok, Future, Ready};
use actix_casbin_auth::{CasbinService, CasbinVals};

use actix_web::{test, web, App};
use casbin::function_map::key_match2;
use casbin::{CachedEnforcer, CoreApi, DefaultModel, FileAdapter};

use std::sync::Arc;
Expand Down Expand Up @@ -77,18 +78,26 @@ where

#[actix_rt::test]
async fn test_set_enforcer() {
let m = DefaultModel::from_file("examples/rbac_restful_keymatch2_model.conf")
let m = DefaultModel::from_file("examples/rbac_with_pattern_model.conf")
.await
.unwrap();
let a = FileAdapter::new("examples/rbac_restful_keymatch2_policy.csv");
let a = FileAdapter::new("examples/rbac_with_pattern_policy.csv");

let enforcer = Arc::new(RwLock::new(CachedEnforcer::new(m, a).await.unwrap()));

let casbin_middleware = CasbinService::set_enforcer(enforcer);

casbin_middleware
.write()
.await
.get_role_manager()
.write()
.unwrap()
.matching_fn(Some(key_match2), None);

let mut app = test::init_service(
App::new()
.wrap(casbin_middleware)
.wrap(casbin_middleware.clone())
.wrap(FakeAuth)
.route("/pen/1", web::get().to(|| HttpResponse::Ok()))
.route("/book/{id}", web::get().to(|| HttpResponse::Ok())),
Expand Down

0 comments on commit e7481b0

Please sign in to comment.