At the end of two years’ time, Pharaoh dreamed that he was standing by the Nile,
."Ad-nay was standing on him" (Genesis 28:13) - Rabbi Abahu said: the matter can be compared to the son of a king who was sleeping on his crib and flies were sitting on him, and when the babysitter came in and stood over him, the flies fled. Similarly, 'and behold angels of Elohim went up and down' and when the Holy Blessed One revealed Godself they fled from him. Rabbi Chiya Rabba and Rabbi Yanay: one said 'on him' that means on the ladder; one said 'on him' that means on Yaakov. For the one who says 'on it', on the ladder, it is easy. For the one who says 'on Yaakov', how can this be? Rabbi Yochanan said: The wicked, their existence stands on their gods. As it says "And Pharaoh dreamt; and he was standing upon the river" (Genesis 41:1). But the righteous, their God stands on them. As it says "Behold God stood upon him and said I am Hashem the God of Avraham." (Genesis 28:13)
ואין פותר אותם לפרעה. פּוֹתְרִים הָיוּ אוֹתָם, אֲבָל לֹא לְפַרְעֹה
ואין פותר אותם לפרעה AND THERE WAS NONE THAT COULD INTERPRET IT TO PHARAOH — There were, indeed, some who interpreted it, but not in reference to Pharaoh (לפרעה)
Pharoah's cupbearer then remembers Joseph, who successfully interpreted his dream when they were in detention together. Scholars point out that Joseph and the cupbearer were probably not in a prison or dungeon but in holding area in Potiphar's house or an official building. Attacking Potiphar's wife would likely have been a capital offence, and Joseph's mere imprisonment is seen by some as a sign that Potiphar knew his wife well enough to recognize that Joseph was innocent.
They quickly brought him out of the pit;
he shaved, changed his clothes, and came before Pharaoh.
and set him over the land of Egypt.
and Pharaoh said to his servants:
Could we find another like him, a man in whom is the spirit of God?
See, I place you over all the land of Egypt!
and he gave him Asenat, daughter of Poti Fera, priest of On, as a wife.
And Yosef’s [influence] went out over the land of Egypt.
whom Asenat, daughter of Poti Fera, priest of On, bore to him.
meaning: God has made-me-forget all my hardships, all my father’s house.
meaning: God has made me bear fruit in the land of my affliction.
so Yaakov said to his sons:
Why do you keep looking at one another?
Here, I have heard that there are rations in Egypt;
go down there and buy us rations from there,
that we may live and not die.
for he said: Lest harm befall him!
but he pretended-no-recognition of them and spoke roughly with them.
He said to them:
From where do you come?
They said: From the land of Canaan, to buy food-rations.
He said to them:
You are spies!
[It is] to see the nakedness of the land that you have come!
As Pharaoh lives!
You shall not depart from this [place]
unless your youngest brother comes here!
Truly,
we are guilty:
concerning our brother!
—that we saw his heart’s distress
when he pleaded with us,
and we did not listen.
Therefore this distress has come upon us!
Did I not say to you, say: Do not sin against the child!
But you would not listen,
so for his blood—now, [satisfaction] is demanded!
Then he returned to them; he spoke to them and had Shim’on taken away from them, and imprisoning him before their eyes.
Me you have bereaved!
Yosef is no more,
Shim’on is no more,
and Binyamin you would take away—
to me has all this happened!
My two sons you may put to death
if I do not bring him back to you!
Place him in my hands, and I myself will return him to you.
My son is not to go down with you!
For his brother is dead,
and he alone is left!
Should harm befall him on the journey on which you are going,
you will bring down my gray hair in grief to Sheol!
that their father said to them:
Return, buy us a little food.
Send the lad with me,
and we will arise and go,
that we may live and not die,
so we, so you, so our little-ones!
at my hand you may seek him!
If I do not bring him back to you
and set him in your presence,
I will be culpable-for-sin against you all the days [to come].
He (Yosef) asked after their welfare and said:
Is your old father well, of whom you spoke?
Is he still alive?
and he said:
Is this your youngest brother, of whom you spoke to me?
And he said:
May God show you favor, my son!
Yosef entered an inner-room and wept there.
Fill the men’s packs with food, as much as they are able to carry,
and put each man’s silver in the mouth of his pack.
He did according to Yosef’s word which he had spoken.
And he also divines, yes, divines with it!
You have wrought ill in what you have done!
and the goblet was found in Binyamin’s pack!
What can we say to my lord?
What can we speak, by what can we show ourselves innocent?
God has found out your servants’ crime!
Here we are, servants to my lord, so we, so the one in whose hand the goblet was found.
[Heaven] forbid that I should do this!
The man in whose hand the goblet was found—he shall become my servant,
but you—go up in peace to your father!
Reuven consistently defends Yosef, but the others fail to do so, with Yehudah the outstanding culprit. Yehudah is tested in Egypt, and in our parshah begins to redeem himself by caring for Ya'akov, protecting Binyamin and being capable of commitment and self-sacrifice to his family in place of the murderous self-absorption he showed as a young man. In fact it is through the story of Yosef, and through Yosef's faithfulness, that the brothers are matured from the wild bunch they tend to be-- Shimon, Levi, Yehudah and Reuven are all guilty of significant wrongdoing and betrayal of their father's concerns and principles.
I would argue that is not Yosef who is testing the brothers, especially Yehudah, but rather Hashem, through the "ruach elohim" he has given Yosef. Hashem's plan succeeds in bringing the brothers to tikkun, and bringing Yehudah to a teshuvah which will make him worthy to be the future leader of Israel and the lineage of the Mashiach. Yosef, being an exemplar of faith and surrender to divine purposes, cooperates with Hashem's designs, probably without understanding fully what they are.
Rebbe Nachman teaches that Ya'akov was the aspect of Hochmah, and was able to make himself the moon to reeive the divine sunlight in all things, thus unveiling the Torah inside them. He passed this on to Yosef, who was also able to empty himself of ego and allow the divine presence and purpose in unfolding events to show themselves.
