T. Daves
T. Daves

Reputation: 40

Selenium Node/Hub Authentication

I am trying to stop a selenium hub registering a node by implementing a custom proxy. I have some code that works for a custom proxy. However, the client can get round this by not specifying the custom proxy in its configuration. Is there a way we can force the node to use the custom proxy and not to use DefaultRemoteProxy.

Or is there something I can implement within the Selenium Project to authenticate a node with the selenium hub?

Upvotes: 0

Views: 542

Answers (1)

Krishnan Mahadevan
Krishnan Mahadevan

Reputation: 14746

There's no elegant way of doing this. Here's a dirty hack using which you can get this done.

  • Create a new marker interface (lets call it as Registrable)
  • Create a new class whose contents duplicate the contents of org.openqa.grid.selenium.proxy.DefaultRemoteProxy (I like to call this approach as CLASSPATH overriding but am sure there's a much more elegant name for this ) such that this new class also is called DefaultRemoteProxy and it resides in the same package org.openqa.grid.selenium.proxy but in your test project.
  • Now inside the constructor add an edit check as shown below.
  • Now create an uber jar out of this project so that it can be used to spin off the Hub.

Here's how Registrable would look like

public interface Registrable {}

Here's how the modified constructor of DefaultRemoteProxy would look like :

public DefaultRemoteProxy(RegistrationRequest request, Registry registry) {
 super(request, registry);
 if (!(this instanceof Registrable)) {
  throw new UnsupportedOperationException("Cannot proceed further");
 }
 pollingInterval = config.nodePolling != null ? config.nodePolling : DEFAULT_POLLING_INTERVAL;
 unregisterDelay = config.unregisterIfStillDownAfter != null ? config.unregisterIfStillDownAfter : DEFAULT_UNREGISTER_DELAY;
 downPollingLimit = config.downPollingLimit != null ? config.downPollingLimit : DEFAULT_DOWN_POLLING_LIMIT;
}

Now you can tweak your custom proxy such that it implements the Registrable interface. So anyone trying to register their node using DefaultRemoteProxy would constantly fail because DefaultRemoteProxy doesn't implement Registrable interface.

Would this work for you ?

Upvotes: 1

Related Questions