From e4183780a978538f761ae70f6947630d7cd384ae Mon Sep 17 00:00:00 2001 From: Ruslan Talpa Date: Tue, 12 Dec 2017 15:31:39 +0200 Subject: [PATCH] Fix #1016 --- CHANGELOG.md | 1 + src/PostgREST/Auth.hs | 2 +- src/PostgREST/Config.hs | 1 + test/Feature/AudienceJwtSecretSpec.hs | 5 ++++- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 754bd1274..22f68865f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - #974, Fix RPC error when function has single OUT param - @steve-chavez - #1021, Reduce join size in allColumns for faster program start - @nextstopsun - #411, Remove the need for pk in &select for parent embed - @steve-chavez +- #1016, Fix anonymous requests when configured with jwt-aud - @ruslantalpa ## [0.4.3.0] - 2017-09-06 diff --git a/src/PostgREST/Auth.hs b/src/PostgREST/Auth.hs index dd93adb81..3f29fa4b0 100644 --- a/src/PostgREST/Auth.hs +++ b/src/PostgREST/Auth.hs @@ -39,7 +39,7 @@ data JWTAttempt = JWTInvalid JWTError of JWT claims. -} jwtClaims :: Maybe JWK -> Maybe StringOrURI -> LByteString -> IO JWTAttempt -jwtClaims _ Nothing "" = return $ JWTClaims M.empty +jwtClaims _ _ "" = return $ JWTClaims M.empty jwtClaims secret audience payload = case secret of Nothing -> return JWTMissingSecret diff --git a/src/PostgREST/Config.hs b/src/PostgREST/Config.hs index 9403af5af..1f5a7ef26 100644 --- a/src/PostgREST/Config.hs +++ b/src/PostgREST/Config.hs @@ -151,6 +151,7 @@ readOptions = do Nothing -> pure Nothing -- no audience in config file Just aud -> case preview stringOrUri (aud :: String) of Nothing -> fail "Invalid Jwt audience. Check your configuration." + (Just "") -> pure Nothing aud' -> pure aud' coerceInt :: (Read i, Integral i) => Value -> Maybe i diff --git a/test/Feature/AudienceJwtSecretSpec.hs b/test/Feature/AudienceJwtSecretSpec.hs index 843ecf855..35be4dd88 100644 --- a/test/Feature/AudienceJwtSecretSpec.hs +++ b/test/Feature/AudienceJwtSecretSpec.hs @@ -41,4 +41,7 @@ spec = describe "test handling of aud claims in JWT" $ do -} let auth = authHeaderJWT "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjk5OTk5OTk5OTksInJvbGUiOiJwb3N0Z3Jlc3RfdGVzdF9hdXRob3IiLCJpZCI6Impkb2UifQ.Dpss-QoLYjec5OTsOaAc3FNVsSjA89wACoV-0ra3ClA" request methodGet "/authors_only" [auth] "" - `shouldRespondWith` 200 \ No newline at end of file + `shouldRespondWith` 200 + + it "requests without JWT token should work" $ + get "/has_count_column" `shouldRespondWith` 200 \ No newline at end of file