How can I test my script which deactivates aws users if their last login or access key was last used over 70 days ago. Moto which is mock boto3 does not have the ability to manipulated the "Password_last_used_" field and in aws sandbox the same is true. How could one go about to devise a valid unit test strategy? Any help is appreciated.
One approach- Currently I am trying to refactor my code so that functions are separated. For example I refactored to create a function called calculate_last_login with the parameter lastLogin . this means I can pass any number to it and see if it calculates the correct number of days since the last login date.
It is possible to manipulate the
password_last_usedfield in Moto - it just requires you to use the internal API.Followup calls to (for example)
boto3.resource("iam").Userwill then return the value that you've set forpassword_last_used.See this Github issue here where this question was raised as well: https://github.com/getmoto/moto/issues/5927