I have been in the rave scene since 1998. I am still a DJ but have become jaded in the past 3-4 years and left the majority fo the scene. I can only speak to how it worked in the East Coast(Northern East Coast) as that is where I was affiliatted with. I was part of some of the major crews up here and we threw a lot iof larger scale parties(raves). Pretty much it goes like this:
I am the guy who decided to throw this party. I have a crew with me who has helped me spend months doing everything to throw this party(dj booking, lighting booking, sound booking, fliers, promoters, street team, tickets, ect.). Now the day of the rave comes and our whole crew is there and inside hours beforehand helping to set everything up and sound checks and meetings with police and security and everything. During this time, our crew will bring in a bunch of drugs(mostly e pills, dust, acid) and just keep them in the back in bags or whatever with all of our equipment for the things we are setting up.
Rave time comes and the doors open, Security is doing the pat downs of all attrendees at the door. We tell security that whatever they find they are at their own discression to do what they wish with it(keep it, throw it out) but ask that they still let the person in after they have removed the illegal drugs. Now, our crew has a bunch of people who's job for the night is to sell the drugs we brought in earlier. Security will leave us alone because after all, we are the ones paying them and we let it be known that we tip well for good service(aka don't mess with any of our crew throwing the party). This is called the "House dealers". Sure there are a lot of people who sneak drugs in past securitry, but most of the time they are there to sell just use what they brought.
What about the police, you ask? Simple, whenever we or security catches and non house dealers selling drugs at our event we ask them for all of their drugs or we will turn them over to police. If they decline, we will take almost all of their drugs then have security drag them outside to the police and say "We caught this kid selling drugs, I bet he still has some on him" The police are happy this was because it shows that we are taking a serious effort to kick out all people selling drugs at our venue. At a larger rave, depending on the police presence outside. We will often hand over between 4-10 people to the police. There are always undercover officers, but they are honestly really easy to spot.