Yes it is illegal to test people's drugs to make sure they've not been substituted or adulterated.
Of course allowing testing could save a lot of lives too, but that's apparently never been the true motivation of the War on Drugs.
I guess maybe this is explicitly making them not useful as probable cause, and also making their use a defense or legal.