Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notify Spar when a team is deleted #519

Merged
merged 3 commits into from
Dec 12, 2018
Merged

Notify Spar when a team is deleted #519

merged 3 commits into from
Dec 12, 2018

Conversation

neongreen
Copy link
Contributor

@neongreen neongreen commented Nov 22, 2018

  • Delete tokens when the team is deleted
  • Delete tokens when the issuer is deleted?
  • PRs to hegemony and cailleach about adding Spar to galley.yaml

@neongreen
Copy link
Contributor Author

@fisx What other things should I do in Spar when a team is deleted? Should I delete relevant entries from team_idp?

@fisx
Copy link
Contributor

fisx commented Dec 6, 2018

@fisx What other things should I do in Spar when a team is deleted? Should I delete relevant entries from team_idp?

tables to be cleaned up from looking at services/spar/schema/src/V*.hs: user, idp, issuer_idp, team_idp, team_provisioning_by_team, team_provisioning_by_token.

it should be straight-forward to decide which rows are dangling and need to removed, no?

the other tables should be harmless: bind cookies, authn_requests, assertions, verdict formats are all only needed during or after an authentication response has been validated, which won't be successful without the issuer mapping to an idp id.

not sure this answers your question?

@neongreen neongreen changed the title [WIP] Notify Spar when a team is deleted Notify Spar when a team is deleted Dec 10, 2018
@neongreen
Copy link
Contributor Author

@fisx Please look at the last commit.

@neongreen neongreen requested a review from fisx December 10, 2018 09:25
@fisx
Copy link
Contributor

fisx commented Dec 10, 2018

@fisx Please look at the last commit.

looks good! i'll review the rest now.

Copy link
Contributor

@fisx fisx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Let me know if you don't want to write the test yourself.)


-- | Notify Spar that a team is being deleted.
deleteTeam :: TeamId -> Galley ()
deleteTeam tid = do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't find a test. I would add it to spar integration tests and make it create a team, owner, idp, two sso users create via a scim token, and then delete it all and look at the scim, saml data in spar, user data on brig, and team data on galley. Helpers of interest:

  • registerIdPAndSCIMToken :: HasCallStack => TestSpar (ScimToken, (UserId, TeamId, IdP))
    registerIdPAndSCIMToken = do
    team@(_owner, teamid, idp) <- registerTestIdP
    (, team) <$> registerSCIMToken teamid (Just (idp ^. idpId))
  • runSparCass
    :: (HasCallStack, m ~ Client, MonadIO m', MonadReader TestEnv m')
    => m a -> m' a
    runSparCass action = do
    env <- ask
    liftIO $ runClient (env ^. teCql) action
    runSparCassWithEnv
    :: ( HasCallStack
    , m ~ ReaderT Data.Env (ExceptT TTLError Cas.Client)
    , MonadIO m', MonadReader TestEnv m'
    )
    => m a -> m' a
    runSparCassWithEnv action = do
    env <- ask
    denv <- Data.mkEnv <$> (pure $ env ^. teOpts) <*> liftIO getCurrentTime
    val <- runSparCass (runExceptT (action `runReaderT` denv))
    either (liftIO . throwIO . ErrorCall . show) pure val
  • you can write helpers to connect to brig, galley cassandras in analogy to runSparCass.

@neongreen
Copy link
Contributor Author

@fisx The test has been written by me and Tiago

@neongreen
Copy link
Contributor Author

Me and Tiago wrote the test

Copy link
Contributor

@fisx fisx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments, but if you are confident that the two tests that you deleted serve no purpose then I'm happy with this.

issuer = idp ^. SAML.idpMetadata . SAML.edIssuer
Data.deleteIdPConfig idpid issuer team
Data.deleteUsersByIssuer issuer
wrapMonadClient $ Data.deleteTeam team
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea!

import Bilge
import Bilge.Assert
import Control.Lens
import Data.ByteString.Conversion
import Imports
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry... :-/

--
-- The token from 'team_provisioning_by_token':
do tokenInfo <- runSparCass $ Data.lookupScimToken tok
liftIO $ tokenInfo `shouldBe` Nothing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[mumbling to myself] there is shouldReturn, which would make this more concise and arguably more readable, but it's in IO and not in MonadIO, so I'm not sure how to rewrite this. i really should write mutants of all the should* functions in MonadIO...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should functions should absolutely be in MonadIO and I've also been mumbling to myself about this for quite some time.

We can use http://hackage.haskell.org/package/hspec-expectations-lifted-0.10.0/docs/Test-Hspec-Expectations-Lifted.html but I'd rather have a homegrown library which would also contain some other common expectations that I end up reimplementing from time to time.

do let issuer = idp ^. SAML.idpMetadata . SAML.edIssuer
mbIdp <- runSparCass $ Data.getIdPIdByIssuer issuer
liftIO $ mbIdp `shouldBe` Nothing
do idps <- runSparCass $ Data.getIdPConfigsByTeam tid
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one doesn't have a comment line. :-)

@@ -203,20 +210,44 @@ testSPStoreID store unstore isalive = do
isit <- runSparCassWithEnv $ isalive xid
liftIO $ isit `shouldBe` True

context "after TTL" $ do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did these two tests go away? can i have them back?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea :/ I'll get them back.

@neongreen
Copy link
Contributor Author

Fixed everything. Sorry for the force-push though

@neongreen neongreen merged commit 27bf3e0 into develop Dec 12, 2018
@neongreen neongreen deleted the spar-delete-team branch December 12, 2018 20:54
Copy link
Contributor

@tiago-loureiro tiago-loureiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW 👍

@jschaul jschaul mentioned this pull request Jan 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants