Skip to content

Commit 0e346f1

Browse files
committed
Ormolu [WIP]
1 parent 9795f69 commit 0e346f1

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

libs/saml2-web-sso/src/SAML2/WebSSO/API.hs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ type API =
7676
:<|> APIAuthReq'
7777
:<|> APIAuthResp'
7878

79-
api :: forall err m. SPHandler (Error err) m => ST -> HandleVerdict m -> ServerT API m
79+
api :: forall err m. (SPHandler (Error err) m) => ST -> HandleVerdict m -> ServerT API m
8080
api appName handleVerdict =
8181
meta appName defSPIssuer defResponseURI
8282
:<|> authreq' defSPIssuer
@@ -124,8 +124,8 @@ parseAuthnResponseBody mbSPId base64 = do
124124
-- rejecting some noise characters and ignoring others.
125125
let xmltxt :: LBS = EL.decodeLenient (cs base64 :: LBS)
126126
resp <-
127-
either (throwError . BadSamlResponseXmlError . cs) pure $
128-
decode (cs xmltxt)
127+
either (throwError . BadSamlResponseXmlError . cs) pure
128+
$ decode (cs xmltxt)
129129
issuer <- maybe (throwError BadSamlResponseIssuerMissing) pure (resp ^. rspIssuer)
130130
idp :: IdPConfig extra <- getIdPConfigByIssuerOptionalSPId issuer mbSPId
131131
creds <- idpToCreds issuer idp
@@ -145,11 +145,11 @@ instance FromMultipart Mem AuthnResponseBody where
145145
m (AuthnResponse, IdPConfig extra)
146146
eval mbSPId = do
147147
base64 <-
148-
either (const $ throwError BadSamlResponseFormFieldMissing) pure $
149-
lookupInput "SAMLResponse" resp
148+
either (const $ throwError BadSamlResponseFormFieldMissing) pure
149+
$ lookupInput "SAMLResponse" resp
150150
parseAuthnResponseBody mbSPId base64
151151

152-
issuerToCreds :: forall m err. SPStoreIdP (Error err) m => Maybe Issuer -> Maybe (IdPConfigSPId m) -> m (NonEmpty SignCreds)
152+
issuerToCreds :: forall m err. (SPStoreIdP (Error err) m) => Maybe Issuer -> Maybe (IdPConfigSPId m) -> m (NonEmpty SignCreds)
153153
issuerToCreds Nothing _ = throwError BadSamlResponseIssuerMissing
154154
issuerToCreds (Just issuer) mbSPId = idpToCreds issuer =<< getIdPConfigByIssuerOptionalSPId issuer mbSPId
155155

@@ -167,30 +167,28 @@ idpToCreds issuer idp = do
167167
-- | Pull assertions sub-forest and pass unparsed xml input to 'verify' with a reference to
168168
-- each assertion individually. The input must be a valid 'AuthnResponse'. All assertions
169169
-- need to be signed by the issuer given in the arguments using the same key.
170-
simpleVerifyAuthnResponse :: forall m err. MonadError (Error err) m => NonEmpty SignCreds -> LBS -> m ()
170+
simpleVerifyAuthnResponse :: forall m err. (MonadError (Error err) m) => NonEmpty SignCreds -> LBS -> m ()
171171
simpleVerifyAuthnResponse creds raw = do
172172
doc :: Cursor <- do
173173
let err = throwError . BadSamlResponseSamlError . cs . show
174174
either err (pure . fromDocument) (parseLBS def raw)
175175
assertions :: [Element] <- do
176176
let elemOnly (NodeElement el) = Just el
177177
elemOnly _ = Nothing
178-
case catMaybes $
179-
elemOnly . node
180-
<$> (doc $/ element "{urn:oasis:names:tc:SAML:2.0:assertion}Assertion") of
178+
case mapMaybe (elemOnly . node) (doc $/ element "{urn:oasis:names:tc:SAML:2.0:assertion}Assertion") of
181179
[] -> throwError BadSamlResponseNoAssertions
182180
some@(_ : _) -> pure some
183181
nodeids :: [String] <- do
184182
let assertionID :: Element -> m String
185183
assertionID (Element _ attrs _) =
186-
maybe (throwError BadSamlResponseAssertionWithoutID) (pure . cs) $
187-
Map.lookup "ID" attrs
184+
maybe (throwError BadSamlResponseAssertionWithoutID) (pure . cs)
185+
$ Map.lookup "ID" attrs
188186
assertionID `mapM` assertions
189187
allVerifies creds raw nodeids
190188

191189
-- | Call verify and, if that fails, any work-arounds we have. Discard all errors from
192190
-- work-arounds, and throw the error from the regular verification.
193-
allVerifies :: forall m err. MonadError (Error err) m => NonEmpty SignCreds -> LBS -> [String] -> m ()
191+
allVerifies :: forall m err. (MonadError (Error err) m) => NonEmpty SignCreds -> LBS -> [String] -> m ()
194192
allVerifies creds raw nodeids = do
195193
let workArounds :: [Either String ()]
196194
workArounds =
@@ -206,7 +204,7 @@ allVerifies creds raw nodeids = do
206204
-- | ADFS illegally breaks whitespace after signing documents; here we try to fix that.
207205
-- https://github.com/wireapp/wire-server/issues/656
208206
-- (This may also have been a copy&paste issue in customer support, but let's just leave it in just in case.)
209-
verifyADFS :: MonadError String m => NonEmpty SignCreds -> LBS -> [String] -> m ()
207+
verifyADFS :: (MonadError String m) => NonEmpty SignCreds -> LBS -> [String] -> m ()
210208
verifyADFS creds raw nodeids = verify creds raw' `mapM_` nodeids
211209
where
212210
raw' = go raw
@@ -224,13 +222,13 @@ verifyADFS creds raw nodeids = verify creds raw' `mapM_` nodeids
224222
data FormRedirect xml = FormRedirect URI xml
225223
deriving (Eq, Show, Generic)
226224

227-
class HasXML xml => HasFormRedirect xml where
225+
class (HasXML xml) => HasFormRedirect xml where
228226
formRedirectFieldName :: xml -> ST
229227

230228
instance HasFormRedirect AuthnRequest where
231229
formRedirectFieldName _ = "SAMLRequest"
232230

233-
instance HasXMLRoot xml => MimeRender HTML (FormRedirect xml) where
231+
instance (HasXMLRoot xml) => MimeRender HTML (FormRedirect xml) where
234232
mimeRender
235233
(Proxy :: Proxy HTML)
236234
(FormRedirect (cs . serializeURIRef' -> uri) (cs . EL.encode . cs . encode -> value)) =
@@ -248,7 +246,7 @@ instance HasXMLRoot xml => MimeRender HTML (FormRedirect xml) where
248246
<input type="submit" value="Continue">
249247
|]
250248

251-
instance HasXMLRoot xml => Servant.MimeUnrender HTML (FormRedirect xml) where
249+
instance (HasXMLRoot xml) => Servant.MimeUnrender HTML (FormRedirect xml) where
252250
mimeUnrender Proxy lbs = do
253251
cursor <- fmapL show $ fromDocument <$> parseLBS def lbs
254252
let formAction :: [ST] = cursor $// element "{http://www.w3.org/1999/xhtml}form" >=> attribute "action"
@@ -392,7 +390,7 @@ simpleHandleVerdict onsuccess = \case
392390
crash :: (SP m, MonadError (Error err) m) => String -> m a
393391
crash msg = logger Fatal msg >> throwError UnknownError
394392

395-
enterH :: SP m => String -> m ()
393+
enterH :: (SP m) => String -> m ()
396394
enterH msg =
397395
logger Debug $ "entering handler: " <> msg
398396

libs/saml2-web-sso/src/SAML2/WebSSO/API/Example.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ simpleGetIdPConfigBy getIdps mkkey idpname = do
142142
crash' = throwError (UnknownIdP . cs . show $ idpname)
143143
mkmap = Map.fromList . fmap (mkkey &&& id)
144144

145-
class SPStoreIdP err m => GetAllIdPs err m where
145+
class (SPStoreIdP err m) => GetAllIdPs err m where
146146
getAllIdPs :: m [IdPConfig (IdPConfigExtra m)]
147147

148148
instance GetAllIdPs SimpleError SimpleSP where
@@ -195,7 +195,7 @@ mkLoginOption :: (Monad m, SP m) => IdPConfig a -> m (ST, ST)
195195
mkLoginOption icfg = (renderURI $ icfg ^. idpMetadata . edIssuer . fromIssuer,) <$> getPath' (SsoPathAuthnReq (icfg ^. idpId))
196196

197197
-- | only logout on this SP.
198-
localLogout :: SPHandler SimpleError m => m (WithCookieAndLocation ST)
198+
localLogout :: (SPHandler SimpleError m) => m (WithCookieAndLocation ST)
199199
localLogout = do
200200
uri <- getPath SpPathHome
201201
cky <- toggleCookie "/" Nothing

0 commit comments

Comments
 (0)