This is part of what I do for a living:
1. Pre-employment tests - legal although should only really be used for safety sensitive roles
2. Reasonable suspicion testing - legal. While you cannot compel a test, you can simply call the cops if/when they try to leave the jobsite and they will test them.
3. Post incident testing - legal, can more easily be compelled.
4. Pre-access testing - legal, but you cannot force them to test if they decide to leave instead of coming on the job site.
I have had employees try to justify being stoned at work on a medical issue and it doesn't matter. Duty to accommodate doesn't extend to medical pot. If it's a safety risk, you send them home and tell them they can't come back until they are sober. The work we do is dangerous and any impairment at all is not worth the risk to yourself or others. If even one of my office workers was stoned/reeked of pot, they will get the same treatment however. Bullshit to the guy who says it doesn't impair judgement or performance. That may be fine in academia, but put a jack hammer in your hands or get in the cab of bulldozer, or work around one and you will want your co-workers sober, not stoned.
If the employees admits a problem/addiction, you have to give them a chance to rehab. Once. When they come back, there's usually an agreement that allows for random or on-demand testing, which is absolutely legal in that case, since it's agreed to in advance by the employee. So far, it's two strikes and you are out, after rehab if you are at work under the influence, you are done. Booze is treated the exact same way.