mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-17 20:41:49 +03:00
d52bfcda4e
* move user info related code to Hasura.User module
* the RFC #4120 implementation; insert permissions with admin secret
* revert back to old RoleName based schema maps
An attempt made to avoid duplication of schema contexts in types
if any role doesn't possess any admin secret specific schema
* fix compile errors in haskell test
* keep 'user_vars' for session variables in http-logs
* no-op refacto
* tests for admin only inserts
* update docs for admin only inserts
* updated CHANGELOG.md
* default behaviour when admin secret is not set
* fix x-hasura-role to X-Hasura-Role in pytests
* introduce effective timeout in actions async tests
* update docs for admin-secret not configured case
* Update docs/graphql/manual/api-reference/schema-metadata-api/permission.rst
Co-Authored-By: Marion Schleifer <marion@hasura.io>
* Apply suggestions from code review
Co-Authored-By: Marion Schleifer <marion@hasura.io>
* a complete iteration
backend insert permissions accessable via 'x-hasura-backend-privilege'
session variable
* console changes for backend-only permissions
* provide tooltip id; update labels and tooltips;
* requested changes
* requested changes
- remove className from Toggle component
- use appropriate function name (capitalizeFirstChar -> capitalize)
* use toggle props from definitelyTyped
* fix accidental commit
* Revert "introduce effective timeout in actions async tests"
This reverts commit b7a59c19d6
.
* generate complete schema for both 'default' and 'backend' sessions
* Apply suggestions from code review
Co-Authored-By: Marion Schleifer <marion@hasura.io>
* remove unnecessary import, export Toggle as is
* update session variable in tooltip
* 'x-hasura-use-backend-only-permissions' variable to switch
* update help texts
* update docs
* update docs
* update console help text
* regenerate package-lock
* serve no backend schema when backend_only: false and header set to true
- Few type name refactor as suggested by @0x777
* update CHANGELOG.md
* Update CHANGELOG.md
* Update CHANGELOG.md
* fix a merge bug where a certain entity didn't get removed
Co-authored-by: Marion Schleifer <marion@hasura.io>
Co-authored-by: Rishichandra Wawhal <rishi@hasura.io>
Co-authored-by: rikinsk <rikin.kachhia@gmail.com>
Co-authored-by: Tirumarai Selvan <tiru@hasura.io>
129 lines
5.3 KiB
Haskell
129 lines
5.3 KiB
Haskell
module Main (main) where
|
|
|
|
import Hasura.Prelude
|
|
|
|
import Control.Concurrent.MVar
|
|
import Control.Natural ((:~>) (..))
|
|
import Data.Time.Clock (getCurrentTime)
|
|
import Options.Applicative
|
|
import System.Environment (getEnvironment)
|
|
import System.Exit (exitFailure)
|
|
import Test.Hspec
|
|
|
|
import qualified Data.Aeson as A
|
|
import qualified Data.ByteString.Lazy.Char8 as BL
|
|
import qualified Database.PG.Query as Q
|
|
import qualified Network.HTTP.Client as HTTP
|
|
import qualified Network.HTTP.Client.TLS as HTTP
|
|
import qualified Test.Hspec.Runner as Hspec
|
|
|
|
import Hasura.Db (PGExecCtx (..))
|
|
import Hasura.RQL.Types (SQLGenCtx (..))
|
|
import Hasura.RQL.Types.Run
|
|
import Hasura.Server.Init (RawConnInfo, mkConnInfo, mkRawConnInfo,
|
|
parseRawConnInfo, runWithEnv)
|
|
import Hasura.Server.Migrate
|
|
import Hasura.Server.Version
|
|
import Hasura.Session (adminUserInfo)
|
|
|
|
import qualified Data.Parser.CacheControlSpec as CacheControlParser
|
|
import qualified Data.Parser.JSONPathSpec as JsonPath
|
|
import qualified Data.Parser.URLTemplate as URLTemplate
|
|
import qualified Data.TimeSpec as TimeSpec
|
|
import qualified Hasura.IncrementalSpec as IncrementalSpec
|
|
-- import qualified Hasura.RQL.MetadataSpec as MetadataSpec
|
|
import qualified Hasura.Server.MigrateSpec as MigrateSpec
|
|
import qualified Hasura.Server.TelemetrySpec as TelemetrySpec
|
|
|
|
data TestSuites
|
|
= AllSuites !RawConnInfo
|
|
-- ^ Run all test suites. It probably doesn't make sense to be able to specify additional
|
|
-- hspec args here.
|
|
| SingleSuite ![String] !TestSuite
|
|
-- ^ Args to pass through to hspec (as if from 'getArgs'), and the specific suite to run.
|
|
|
|
data TestSuite
|
|
= UnitSuite
|
|
| PostgresSuite !RawConnInfo
|
|
|
|
main :: IO ()
|
|
main = withVersion $$(getVersionFromEnvironment) $ parseArgs >>= \case
|
|
AllSuites pgConnOptions -> do
|
|
postgresSpecs <- buildPostgresSpecs pgConnOptions
|
|
runHspec [] (unitSpecs *> postgresSpecs)
|
|
SingleSuite hspecArgs suite -> runHspec hspecArgs =<< case suite of
|
|
UnitSuite -> pure unitSpecs
|
|
PostgresSuite pgConnOptions -> buildPostgresSpecs pgConnOptions
|
|
|
|
unitSpecs :: Spec
|
|
unitSpecs = do
|
|
describe "Data.Parser.CacheControl" CacheControlParser.spec
|
|
describe "Data.Parser.URLTemplate" URLTemplate.spec
|
|
describe "Data.Parser.JsonPath" JsonPath.spec
|
|
describe "Hasura.Incremental" IncrementalSpec.spec
|
|
-- describe "Hasura.RQL.Metadata" MetadataSpec.spec -- Commenting until optimizing the test in CI
|
|
describe "Data.Time" TimeSpec.spec
|
|
describe "Hasura.Server.Telemetry" TelemetrySpec.spec
|
|
|
|
buildPostgresSpecs :: (HasVersion) => RawConnInfo -> IO Spec
|
|
buildPostgresSpecs pgConnOptions = do
|
|
env <- getEnvironment
|
|
|
|
rawPGConnInfo <- flip onLeft printErrExit $ runWithEnv env (mkRawConnInfo pgConnOptions)
|
|
pgConnInfo <- flip onLeft printErrExit $ mkConnInfo rawPGConnInfo
|
|
|
|
let setupCacheRef = do
|
|
pgPool <- Q.initPGPool pgConnInfo Q.defaultConnParams { Q.cpConns = 1 } print
|
|
|
|
httpManager <- HTTP.newManager HTTP.tlsManagerSettings
|
|
let runContext = RunCtx adminUserInfo httpManager (SQLGenCtx False)
|
|
pgContext = PGExecCtx pgPool Q.Serializable
|
|
|
|
runAsAdmin :: Run a -> IO a
|
|
runAsAdmin =
|
|
peelRun runContext pgContext Q.ReadWrite
|
|
>>> runExceptT
|
|
>=> flip onLeft printErrJExit
|
|
|
|
schemaCache <- snd <$> runAsAdmin (migrateCatalog =<< liftIO getCurrentTime)
|
|
cacheRef <- newMVar schemaCache
|
|
pure $ NT (runAsAdmin . flip MigrateSpec.runCacheRefT cacheRef)
|
|
|
|
pure $ beforeAll setupCacheRef $
|
|
describe "Hasura.Server.Migrate" $ MigrateSpec.spec pgConnInfo
|
|
|
|
parseArgs :: IO TestSuites
|
|
parseArgs = execParser $ info (helper <*> (parseNoCommand <|> parseSubCommand)) $
|
|
fullDesc <> header "Hasura GraphQL Engine test suite"
|
|
where
|
|
parseNoCommand = AllSuites <$> parseRawConnInfo
|
|
parseSubCommand = SingleSuite <$> parseHspecPassThroughArgs <*> subCmd
|
|
where
|
|
subCmd = subparser $ mconcat
|
|
[ command "unit" $ info (pure UnitSuite) $
|
|
progDesc "Only run unit tests"
|
|
, command "postgres" $ info (helper <*> (PostgresSuite <$> parseRawConnInfo)) $
|
|
progDesc "Only run Postgres integration tests"
|
|
]
|
|
-- Add additional arguments and tweak as needed:
|
|
hspecArgs = ["match", "skip"]
|
|
-- parse to a list of arguments as they'd appear from 'getArgs':
|
|
parseHspecPassThroughArgs :: Parser [String]
|
|
parseHspecPassThroughArgs = fmap concat $ for hspecArgs $ \nm->
|
|
fmap (maybe [] (\a -> ["--"<>nm , a])) $ optional $
|
|
strOption ( long nm <>
|
|
metavar "<PATTERN>" <>
|
|
help "Flag passed through to hspec (see hspec docs)." )
|
|
|
|
|
|
runHspec :: [String] -> Spec -> IO ()
|
|
runHspec hspecArgs m = do
|
|
config <- Hspec.readConfig Hspec.defaultConfig hspecArgs
|
|
Hspec.evaluateSummary =<< Hspec.runSpec m config
|
|
|
|
printErrExit :: String -> IO a
|
|
printErrExit = (*> exitFailure) . putStrLn
|
|
|
|
printErrJExit :: (A.ToJSON a) => a -> IO b
|
|
printErrJExit = (*> exitFailure) . BL.putStrLn . A.encode
|