The Malbim, in his commentary to Iyov 2:3 explains that he did not deserve it:
G-d rebukes Satan for having maligned Job without cause. Job had stood the test; his worship of G-d had indeed been out of love and without any expectation of reward, and so the calamities inflicted upon his possessions and children had been totally unwarranted.
The Gemara in Bava Basra actually speaks very positive about the fact that even all the trials he withstood, he did not deviate and curse G-d:
About this it says: “And the Lord said to the Satan: Have you considered My servant Job, that there is none like him on earth, a perfect and an upright man, one that fears God and turns away from evil? And still he holds fast to his integrity, although you moved Me against him, to destroy him without cause” (Job 2:3).
The Gemara goes on to explain:
It was taught in a baraita with regard to the methods of the Satan: He descends to this world and misleads a person into sinning. He then ascends to Heaven, levels accusations against that very sinner, and inflames G-d’s anger against him. He then receives permission to act and takes away the sinner’s soul as punishment.
As the Malbim says, this was without cause, but nevertheless, Iyjov stood the test and his worship of G-d was nothing but out of love. He hold fast to his integrity and did not deviated from the right path.