Back in the early 2000 s I worked on the construction of the Channel Tunnel Rail Link and held a Personal Track Safety qualification (PTS). That required drug and alcohol screening initially and then randomly to a low level (about 1/4 of that under the Road Traffic Act). I was told the random D & A screening was a legal requirement for anybody in the UK in any part of the transportation industry whose role was considered to be safety critical. So I expect it to be legally allowed, even if it isn't regularly enforced.