Job 1:1 and Job 1:12
(Job 1:1) - "There was a man in the land of Uz, whose name was Job, and that man was blameless, upright, fearing God, and turning away from evil."
(Job 1:12) - "Then the Lord said to Satan, "Behold, all that he has is in your power, only do not put forth your hand on him."
When the Bible says that Job was blameless, it does not mean that he was absolutely sinless. It means that he was a God-fearing man who sought to do what was right before the Lord. Job's awareness of his own sins is acknowledged by the fact that he sacrificed animals to the Lord as atonement for his sins in chapter 1.
As the story goes, the "sons of God", angels, presented themselves before God. Satan was there and a conversation ensued about Job's goodness. Satan challenges God by stating that Job will denounce God if afflicted. God gives permission to Satan to afflict Job. Of course, Job doesn't denounce God. So, the question is why would God allow Satan to do this?
The reason is so that God may be vindicated at His word and so that we might understand that trials and tribulations will come to those who are godly. In the former, we see the righteousness of God After all, none are righteous before God (Rom. 3:10-12). In the latter we see the perfection of Job's faith (James 1:2-4).