Lol this is an old urban legend. Cops do not have to identify themselves if undercover and you ask. Now if your being arrested or kicked in they must identify themselves prior to doing so ie"Police department! Search warrant": then kick in...Now it got mixed up like this as it is a common practice to ask someone if they are a cop to see their reaction or if they seem nervous or over compensate trying to prove they are not which is why the prostitutes used to use the code always ask and observe while asking for tip offs.
Bingo.
First of all this idea that undercover cops can't deny that they police are is so stupid, it defines reason that anyone could actually believe it.
Cops are not only legally permitted to lie in furtherance of their duty, their training and job description often REQUIRES them to do so.
Hint. . .what does the word "undercover" mean? It means that
they are pretending to be something they are not. If undercover cops were obligated to blow their cover just because of a simple question like this,
there would be no such thing as undercover police, period.
The reason you ask someone if they're an undercover cop is to gauge their reaction and try to read their body language to see if their response appears truthful. Of course any GOOD undercover cop has been asked this question a hundred times already and will put out a convincing denial, so in the real world asking is probably not all that effective, but maybe some rookie might not handle himself right and could give himself up this way.
On undercover cops actually using drugs, no, they're not "supposed" to do so, but in practice:
a. Most people (even non-cops) can come up with fairly convincing reasons why they can't use any particular drug at any moment. ("Just had some", "makes me paranoid/sick", "gotta get some rest/drive/etc", "my work has been doing piss tests, and I can't afford to lose my job", etc).
b. Cops can still fake using drugs (in some cases fairly convincingly), if they need to.
c. Even they do use drugs on duty, that probably won't invalidate any arrest they make or evidence they gather, and
d. In practice, if any given dept has a reason to suspect a particular officer might have used drugs on duty (which it probably won't) there are any number of good reasons it would probably want to look the other way.
Bottom line is, someone's refusal to use drugs might be innocent; and conversely you can't conclude that just because someone appears to be using, that they are NOT a cop.