Personally, I think you should be given the chance to rest whenever you want, but the player should be
If your rest is disturbed by an enemy engaging you, your character should wake up in shock: with low stamina, for example. Perhaps your character holsters their weapon when sleeping, and then you need to draw it again before you can retaliate. Not only would it make for some potentially interesting ambushes in the wilderness and other dangerous areas, but it would mean you wouldn't have to run to the other side of a dungeon to get some sleep when it's clear that there's no imminent threat.
I mean, if I encounter some rat in a room of a dungeon but cast a lock spell on the door, I highly doubt they're going to manage to gnaw the door open and run me through: so I should have the chance to rest at my own discretion.
Thoughts?