As a citizen of the United States your right to deny an unreasonable search of your “persons, houses, papers, and effects” is protected by the Fourth Amendment of the Constitution. That being said, generally, Police cannot search anything of yours without probable cause, a warrant, or your consent. Probable cause is loosely defined as, sufficient reason based upon known facts to believe a crime has been committed or that certain property is connected with a crime, according to dictionary.com. Additionally, if an Officer sees something through a window or smells something it is then in ‘Plain View’ which constitutes a warrantless search because it gives them probable cause. During an arrest an Officer may search you and/or the surrounding area in an effort to find anything dangerous or something which would contribute to the arrest. As long as this search can be proven for the Officers safety or in order to receive evidence related to the arrest which was hidden, it is considered reasonable.
If a warrant has been granted to search your property, or a warrant for your arrest has been issued a cop may legally search any areas specifically discussed in the warrant. Anything they find which is not outlined in the warrant to be what they are there searching for typically may not be used against you because it was found illegally.
The best way to deal with a situation in which an Officer attempts to search you or your property in a way that you think is illegal is to calmly state that you do not consent to this search. The officer must prove in court that the search was reasonable or lawful and it is there that you can make your case, never at the time of the search which will only escalate the innocent.