That story is obviously mythical probably produced to make the Jews believe that observing the law though difficult will bring great rewards while not observing it will bring punishment. It's a myth-parable.
I feel that is mostly the stance of Job's friends, reflecting the common belief in individual reward and punishment which has become a central feature of official Judaism since the Deuteronomistic movement. That Job, as the hero (or anti-hero), consistently criticises such views in the poetical dialogues, makes the work a highly subversive one. Of course this is partly lost in the prose conclusion which describes Job's restoration. Still, this conclusion gives reason to Job against his friends.
The way I put it is would someone on a neighbour's advice have his wife tortured to see whether she really loves him when already he knows that she had always been faithful and loving towards him? That would be monstrous.
This is the view or the prose prologue, which is completely absent from the body of the book (and even the epilogue).
And whoever wrote Job created a lot of dangerous misconceptions about the way God operates and this book should have been among the non canonical apocrypha.Regardless of the issue of canonicity (I would rather consider it a sort of "miracle" that such a subversive book was included in the Jewish canon, probably thanks to its soapy prologue-epilogue), the core of the book raises essential questions about the apories of ethical monotheism. Either God is a ruthless tyrant (Job, in the dialogues) or he is absolutely beyond any moral understanding (Yhwh's discourses). In any case, exit the moral optimism of Deuteronomy and its official lineage (e.g. Chronicles).