Well Jesus choose Judas, he ended up betraying Him, Peter denied Him, there but for the grace of God go I… God allows satan in his pride to tempt him just like in the desert.
The Saint Michael prayer was inspired from the visions of Pope Leo xiii God granted satan 100 years to destroy the Church, satan failed… why God allowed satan to do this is beyond me, God loved Lucifer, who became arrogant, therefore ejected from Heaven !
Ver. 31. Satan hath desired to have you, that he may sift you as wheat. In these words is expressed both what Satan desired, and what God permitted. Satan desired leave to tempt them, that he might make them fall from their faith in Christ. Almighty God permitted this temptation, this trial, to convince them how weak they were of themselves: he permitted their frailty to be partly overcome, yet so that rising again by his grace, they should be cleansed and purified as wheat when it is sifted: and that shortly after, being strengthened and confirmed by the coming of the Holy Ghost, they might become new men, enabled to stand firm against all the attacks of their greatest adversaries. (Witham)
Ver. 32. That thy faith fail not. The faith of Peter, established by the coming of the Holy Ghost, hath never failed, nor can fail, being built upon a rock, which is Christ himself, and being guided by the spirit of truth, as Christ promised. (John xv. 26. and xvi. 13.) — And thou being once converted, confirm thy brethren, even all the other apostles and bishops, over whom I have made and constituted thee and thy successors the chief head, that such a head being appointed by divine authority, all occasions of schisms and divisions might cease, says St. Jerome. (Witham) — Admire the superabundance of the divine patience. That the disciple might not lose courage, he promised him pardon before he has committed the crime, and restores him again to his apostolic dignity, saying, confirm thy brethren. (St. Cyril)
If we look at the book of Job (and Zechariah 3:1) it seems that Satan is the accuser, or the adversary, who is working under God’s sovereignty. It seems even Satan has a purpose in God’s sagacious plan. Likewise, I would say that the testing of Jesus in the desert had a purpose in God’s plan of redemption (Jimmy Akin has a nice little article on that here).