Wikileaks founder Julian Assange on Friday testified in his legal case against a Spanish private security firm that he claims spied on him while he was holed up in the Ecuadoran embassy in London.

Spain’s top criminal court is investigating whether Undercover Global Ltd, which was responsible for security at the embassy, spied on Assange and passed on information to the United States.

The case is key to Assange’s efforts to fight an extradition request by the US Justice Department which is pushing to have him put on trial for leaking hundreds of thousands of secret US military and diplomatic documents in 2010.

“The case being investigated in Spain states that Mr Assange has been subjected to widespread interference on a massive scale by the American authorities, violating his confidential communications with his lawyers, among other rights,” his legal team said.

Last month, an independent UN rights expert Nils Melzer warned that the conditions WikiLeaks founder Julian Assange was being held in are putting his life “at-risk”.

Melzer, said in a statement, “Unless the UK urgently changes course and alleviates his inhumane situation, Assange’s continued exposure to arbitrariness and abuse may soon end up costing his life,’ the UN special rapporteur on torture and other cruel, inhuman or degrading treatment”.

Melzer, who visited the 48-year-old Australian whistleblower in a London prison on May 9, nearly a month after his arrest at Ecuador’s embassy where he had been holed up for seven years, has previously warned he was being subjected to drawn-out “psychological torture”.

In April this year, UK police arrested Assange after the South American nation revoked the political asylum that had protected him in the embassy, and he was brought before a British court — the first step in an extradition battle that he has vowed to fight.

Assange took refuge in the embassy in 2012 after he was released on bail in Britain while facing extradition to Sweden on sexual assault allegations that have since been dropped. He refused to leave the embassy, fearing arrest and extradition to the US for publishing classified military and diplomatic cables through WikiLeaks.

He has been facing the extradition request by the US over charges he violated the US Espionage Act by publishing a huge cache of military and diplomatic files in 2010.