Well, if Job wasn't wrong and had not opened the door to Satan's attacks, why did he suffer? Also, Job said, "Though He slay me, yet will I trust Him." What does it mean for God to "slay" someone? Did God bring this evil on Job?
Job's suffering was a test of his character. The issue with Job was not the loss of his material possessions, his children or his health. We know this because God replaced - double - everything Job loss. The issue with Job was his reaction toward God in the face of His loss. That was the test. It was a test of Job's character. Would Job curse God and die as his wife advised, or would he maintain his trust in God? What was the "slaying" part? The slaying was God allowing Job to experience the loss. The purpose was not to teach Job something, but to expose his character. God knew what was in Job. (Job 1:8) Satan didn't. (Job 1:9-11)
Job maintained his trust in God. He passed the test. God bragged on Job. In the test, Job did not let God down. Job took a licking and kept right on ticking! Because he passed the test, not only did God restore his loss -- double, He also had Job's story placed in the cannon as a testament to his faith! (2 Peter 1:2021; 1 Corinthians 10:11)
Does God allow His children to "go through things" as a test of their character? Yes He does! The Word of God says, "By the mouth of two or three witnesses every word shall be established". (2 Corinthians 13:1) There are two scriptural witnesses that this is so.
"Beware that you do not forget the Lord your God by not keeping His commandments, His judgments, and His statutes which I command you today…who fed you in the wilderness with manna, which your fathers did not know that He might humble you and THAT HE MIGHT TEST YOU, to do you good in the end…" Deuteronomy 8:11,16.
"Thus says the Lord, the God of Israel: 'Like these good figs, so will I acknowledge those whom I have sent out of this place FOR THEIR OWN GOOD, into the land of the Chaldeans, for I will set My eyes on them FOR GOOD, and I will bring them back to this land; I will build them and not pull them down, and I will plant them and not pluck them up.'" Jeremiah 24:5,6.
God tested the Children of Israel in the wilderness to see if they would obey Him. They wouldn't. So with the exception of Joshua and Caleb, the entire adult generation who were brought out of Egypt died in the wilderness, not inheriting the Promised Land. That was not God's original intention. He intended to bless them, but they failed the character test. So they died in the wilderness and their children inherited the Promise Land.
In this dispensation of Grace, we Christians can also go through character tests. When we do, because of the story of Job, we have the assurance that everything will be alright. When we pass the test like Job did, we become "perfect (mature) and complete, lacking nothing". (James 1:4) That means in the area(s) in which we were tested, Satan can't touch us.
"We know that who ever is born of God does not sin; but he who has been born of God keeps himself, and the wicked one does not touch him." 1 John 5:18.