This scenario was all too common down here in south Florida in the late seventies, eighties - and even into the early nineties (those early episodes of Miami Vice were all too real back then...). It got to the point with police impersonators that there was actually a public message from one big department about how to behave out on the road if anyone showing a blue light tried to pull you over (the advice was to slow down but not stop and drive to your local police agency, after calling 911, with whoever it was behind you following along - if they were legit...). We actually had more than one very bad scene where drug robbers hooked up with drug selling robbers - with very bad outcomes (neither side brought drugs or money - both sides were heavily armed and intent on ripping each other off...). The "Miami Special" dope deal - where cops got to respond after all the bloodshed and clean up the mess...
As a result of what was actually going down back then, we made certain to always include a fully uniformed officer on any warrant service or drug raid - and that individual was in a marked vehicle first on the scene to remove any doubt that they were "real cops"... During that time period I had occasion to make contact with a few possible witnesses to a police action that generated an Internal Affairs complaint afterwards... I was in plain clothes at the time - and it wasn't a good neighborhood at all... A middle aged man answered the door at one house and I displayed my I.D. with badge, clipboard in hand and introduced myself and my purpose in calling... He took one look at my badge, then said... "Anyone can get one of those - if you're a cop - show me your gun"... True story, and at that time I was wearing an ankle holster (with a medium sized auto pistol) - but otherwise not showing any sign I was an investigator... Once I raised my cuff and showed the weapon -we got along just fine - but that was Miami back then...
It got so bad that we actually had our SRT (our version of SWAT) participating on any street level warrant service or drug deals (if possible) so that the cops on the scene wouldn't find themselves out-gunned, out-manned, and on the short end of what might be going down.. On one occasion one of our SRT shot down a robber dressed like a SWAT team member (a quick 9mm double tap from a fully suppressed MP5) when the bad guy went for his gun during the takedown - there were four or five robbers dressed as SWAT guys on the scene of an intended dope rip... Our undercover vice guys were posing as dealers making a connection...with our SRT as back-up for the takedown... Unfortunately the offender survived..
We also required any plain clothes officer to put on a raid jacket clearly marked "POLICE" if they ever responded to any in-progress calls - or stay away if they couldn't wear something that identified them as officers... This was done as much for otticers from other jurisdictions (on a really hot call there were times when officers from multiple different police forces might come to the scene...) as well as providing some reassurance for citizens (who tend to freak out when long haired cops in civilian clothes start running around, gun in hand, in their neighborhood...). When I came out of our local Academy there were 26 local police agencies in Dade county (the Miami area) alone.. There are more now - all these years later. Makes for some interesting encounters out on the street...
Of course back in the cocaine cowboy era... there actually were cops who were criminals - some were doing everything from murder on down as sidelines while still on the job.. I'd like to think those days are long over... I've heard that other big cities had similar problems back then as well...