Not an expert, but if you can test for contamination why wouldn't you be able to test for the drugs themselves?
Raman spectroscopy[1] is one that I know of that is frequently used to determine chemical composition. Spectroscopy in general still amazes me.
[1] https://en.wikipedia.org/wiki/Raman_spectroscopy#Application...