There's a discussion on the (probably soon to be vanished) comments on this question about what US immigration can and cannot do. Is it possible to get a definitive answer on this?
I assume they can search me and all my stuff, but can they make me turn on electronics? If so can they make me provide my password or insist I login myself? Decrypt any encrypted files or drives?
How far can they search? Are they allowed to use tools that attempt to find deleted files or extract search history from cookies or other 'computer forensic investigation' type approaches?
If I'm travelling with my work laptop there's a banner when you login saying that use by a non-employee is a criminal offence -- are they immune from prosecution under that?
On a separate note if I have to provide a password that gives them access to more than just the laptop. If it's my work one they can gain access to the work network and associated websites, if it's my personal one they get my Microsoft login (and e-mail, cloud files, etc) as it's Windows 10 and tied to the account.
I tend to assume that any refusal on my part will lead to a denial of entry, but taken to the extreme that seems like they can ask anything ("do a little dance and we'll think about it") it seems like there must be some sort of limit. I guess it's a separate question to ask what someone should do during the interview if they think the immigration officer is crossing the line.
EDIT: To be clear, I'm not a US citizen and I'm asking for information relating to non-citizens (who have the appropriate paperwork, or whatever, to enter the country).