From a0a7a83c9756a62a7d3bcd4b676f4fa947bd64b2 Mon Sep 17 00:00:00 2001 From: Stuart Popejoy Date: Thu, 24 Oct 2019 20:36:32 -0400 Subject: [PATCH] Sig check only considers acquired (and pending) caps --- src/Pact/Repl/Lib.hs | 4 ++-- src/Pact/Runtime/Capabilities.hs | 8 +------- tests/pact/keysets.repl | 28 ++++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/Pact/Repl/Lib.hs b/src/Pact/Repl/Lib.hs index 1af805077..2dfc666f2 100644 --- a/src/Pact/Repl/Lib.hs +++ b/src/Pact/Repl/Lib.hs @@ -448,7 +448,7 @@ expectFail i as = case as of TLitString msg -> do r <- catch (Right <$> reduce expr) (\(e :: SomeException) -> return $ Left (show e)) case r of - Right v -> tfailure msg $ "expected failure, got result = " <> pack (show v) + Right v -> tfailure msg $ "expected failure, got result = " <> pack (showPretty v) Left e -> case errM of Nothing -> tsuccess msg Just err | err `isInfixOf` e -> tsuccess msg @@ -590,7 +590,7 @@ setGasModel _ as = do testCapability :: ZNativeFun ReplState testCapability i [ (TApp app _) ] = do (_,d,_) <- appToCap app - let (scope,verb) = maybe (CapCallStack,"aquired") (const (CapManaged,"installed")) (_dDefMeta d) + let (scope,verb) = maybe (CapCallStack,"acquired") (const (CapManaged,"installed")) (_dDefMeta d) r <- evalCap i scope False $ app return . tStr $ case r of AlreadyAcquired -> "Capability already " <> verb diff --git a/src/Pact/Runtime/Capabilities.hs b/src/Pact/Runtime/Capabilities.hs index 5bdbd0651..45e453114 100644 --- a/src/Pact/Runtime/Capabilities.hs +++ b/src/Pact/Runtime/Capabilities.hs @@ -48,12 +48,6 @@ type ApplyMgrFun e = Def Ref -> PactValue -> PactValue -> Eval e PactValue noopApplyMgrFun :: ApplyMgrFun e noopApplyMgrFun _ mgd _ = return mgd --- | Get any cap that is currently granted, of any scope. -grantedCaps :: Eval e (S.Set UserCapability) -grantedCaps = S.union <$> getAllStackCaps <*> getAllManaged - where - getAllManaged = S.fromList . concatMap toList <$> use (evalCapabilities . capManaged) - -- | Check for acquired/stack (or composed therein) capability. capabilityAcquired :: UserCapability -> Eval e Bool capabilityAcquired cap = elem cap <$> getAllStackCaps @@ -197,7 +191,7 @@ checkSigCaps checkSigCaps sigs = go where go = do - granted <- grantedCaps + granted <- getAllStackCaps return $ M.filter (match granted) sigs match granted sigCaps = diff --git a/tests/pact/keysets.repl b/tests/pact/keysets.repl index b3fd6909a..05b727c1d 100644 --- a/tests/pact/keysets.repl +++ b/tests/pact/keysets.repl @@ -151,6 +151,15 @@ (defun run-AB () (with-capability (AB) true)) + + (defcap M (a:integer) @managed a M_mgr + (enforce-keyset KEYSET_A)) + + (defun M_mgr (m r) m) + + (defcap O () + (enforce-keyset KEYSET_A)) + ) (env-keys ["a"]) @@ -173,3 +182,22 @@ (run-A "bar" true)) (expect "AB succeeds with a in scope" true (run-AB)) + +(env-sigs [{ 'key: "a", 'caps: [(M 1)] }]) +;; env-sigs does NOT install managed caps like Intepreter does +(expect + "Managed install works with scoped keyset" + "Capability installed" + (test-capability (M 1))) + +(expect-failure + "O not in scope, managed M shouldn't allow it to pass" + "Keyset failure" + (test-capability (O))) + +(env-sigs [{ 'key: "a", 'caps: [(M 1),(O)] }]) + +(expect + "Scoped acquire of O succeeds" + "Capability acquired" + (test-capability (O)))