Well, anyways, to address your points...
1. Just because the cops are doing the test wouldn't mean that it's automatically a conflict of interest. Not all cops are going to give all cops a pass. If a cop finds a corrupt cop, he's probably going to be more pissed at him than he would a regular criminal, for a myriad of reasons, from putting him or his buddies at risk, to just the fact they're held to a higher standard. Furthermore, outside police department, the FBI, or even outside organizations could do the test, which honestly isn't that difficult. They could just as easily try to slip past those people so, it doesn't change much in that department.
2. Under cover cops are given special permissions, like not needing to wear uniforms, adhere to dress codes, carry standard issue weapons, or generally tell people they are police. If they take drugs to blend in which, there are fake drugs, they can just break the law, as much as running stop lights during a high speed chase, or selling people illegal drugs to bait them into doing illegal things.
3. Someone could blackmail a cop by figuring out any number of things, or threaten their family and the like. It's probably more likely that a cop is doing something else that could blackmail them than drugs, and if the test is done properly and they get caught for it, they're off the job one way or another. It's already illegal to do drugs, so like, if you get caught at all it's illegal, so any number of people could figure out about it.
4. You simply increase the accuracy of the tests, or, do more thorough tests if it seems like someone tested positive. Cops shouldn't worry about being caught for doing illegal things, since, it's part of their jobs to stop illegal things. It should be implied that they aren't going to do illegal things.