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

Refuse to delete non-empty IdPs (412 precondition failed) #875

Merged
merged 6 commits into from
Jan 14, 2020

Conversation

fisx
Copy link
Contributor

@fisx fisx commented Oct 15, 2019

@fisx fisx changed the title Fail to delete non-empty IdPs (412 precondition failed) Refuse to delete non-empty IdPs (412 precondition failed) Oct 17, 2019
@fisx
Copy link
Contributor Author

fisx commented Oct 18, 2019

I think I'm done with this.

@fisx
Copy link
Contributor Author

fisx commented Oct 18, 2019

can be merged by reviewer

@fisx
Copy link
Contributor Author

fisx commented Oct 21, 2019

(we may want to add a shell script that deletes non-empty idps by first deleting all the users inside. it's dangerous, but i have a feeling we're going to use it a couple of times before we've figured out how to do all of this in team-settings.)

@fisx
Copy link
Contributor Author

fisx commented Oct 21, 2019

before merging this to dev, make sure QA and clients are aware of the change and happy with it.

team = idp ^. SAML.idpExtraInfo

-- fail if idp is not empty
idpIsEmpty <- wrapMonadClient $ isNothing <$> Data.getSAMLAnyUserByIssuer issuer
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is there a map here, when we are getting a single user?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why is there a map here, when we are getting a single user?

The return value of Data.getSAMLAnyUserByIssuer is m (Maybe UserId) for some functor m. <$> maps into any functor, so in this case it's not [], but m. Inside the m, we have a maybe value, which is transformed into a boolean by isNothing.

Is that a good answer? And am I answering the right question?

Copy link
Contributor

Choose a reason for hiding this comment

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

yep. works for me.

env <- ask
(firstOwner, tid, idp) <- registerTestIdP
ssoOwner <- mkSsoOwner firstOwner tid idp
callIdpDelete' (env ^. teSpar) (Just ssoOwner) (idp ^. idpId)
`shouldRespondWith` \resp -> statusCode resp < 300
`shouldRespondWith` checkErr (== 412) "idp-has-bound-users"
Copy link
Contributor

Choose a reason for hiding this comment

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

these error code changes confuse me, as i don't see 404 or 412 in the changed code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

these error code changes confuse me, as i don't see 404 or 412 in the changed code.

In this line, we change the behavior that we need to align these tests with: before this change, deleting IdPs populated with wire users was fine; now it's not).

callIdpGet' (env ^. teSpar) (Just ssoOwner) (idp ^. idpId)
`shouldRespondWith` checkErr (== 404) "not-found"
`shouldRespondWith` \resp -> statusCode resp < 300
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 don't have an explanation for this change, though. This is indeed odd.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, no, should have read the test: if spar refuses to delete the idp, it won't be deleted, so getting it will still work. :)

@fisx fisx merged commit fcc6adf into develop Jan 14, 2020
@fisx fisx deleted the fisx/do-not-delete-non-empty-idps branch January 14, 2020 09:15
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.

I can no longer require changes but please push a hotfix for this :)

@@ -212,6 +213,14 @@ insertSAMLUser (SAML.UserRef tenant subject) uid = retry x5 . write ins $ params
ins :: PrepQuery W (SAML.Issuer, SAML.NameID, UserId) ()
ins = "INSERT INTO user (issuer, sso_id, uid) VALUES (?, ?, ?)"

-- | We only need to know if it's none or more, so this function returns the first one.
getSAMLAnyUserByIssuer :: (HasCallStack, MonadClient m) => SAML.Issuer -> m (Maybe UserId)
getSAMLAnyUserByIssuer issuer = runIdentity <$$>
Copy link
Contributor

Choose a reason for hiding this comment

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

@fisx please change this C* query to use LIMIT 1 otherwise you risk returning a potentially unbound nr. of users.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#942

good catch, glad you've paid attention! thanks :)

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