Selenium Node/Hub Authentication

痴心易碎 提交于 2019-12-13 08:40:12

问题


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?


回答1:


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 ?



来源:https://stackoverflow.com/questions/43986508/selenium-node-hub-authentication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!