One can distinguish five reasons why God allows the devil to attack us:
first, so that from attack and counter-attack we may become practiced in discerning good from evil;
second, so that our virtue may be maintained in the heat of the struggle and so be confirmed in an impregnable position;
third, so that as we advance in virtue we may avoid presumption and learn humility;
fourth, to inspire in us an unreserved hatred for evil through the experience we thus have of it;
fifth, and above all, that we may attain inner freedom and remain convinced both of our own weakness and of the strength of him who has come to our aid.
Maximus the Confessor (580-682)
Centuries on Charity 2, 67 (Sources Chrétiennes 9, p. 114)