The "give up your passwords" thing is not a real thing. It's only happened occasionally in one-off scenarios where power-tripping border agents overstepped their bounds, and I think has maybe been proposed, but is in no way an actual law.
Even US citizens can be strongly encouraged (with threat of detainment) to turn over their electronic devices and surrender their passwords when crossing the border -- and remember, "the border" is legally defined as any location within 100 miles of a point of entry.
From https://www.npr.org/sections/thetwo-way/2018/01/05/576139303...
> CBP agents inspected 30,200 phones and other devices during [fiscal year 2017].
Therefore, it does happen somewhat frequently.
> Officials stress that those searches represent just a tiny fraction of all arriving international travelers — .007 percent.