Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REGR:NullPointerException thrown while doing eval() with client object created with incorrect credentials #582

Closed
srinathgit opened this issue Dec 6, 2016 · 5 comments

Comments

@srinathgit
Copy link
Contributor

srinathgit commented Dec 6, 2016

A. The following test which used to succeed , now throws NullPointerException at line "client.newServerEval().xquery(insertJSON).eval();".
B. Looking further, the client object is created with Authentication set to "BASIC" though server authentication is set to "DIGEST". It is now throwing a 401 UnAuthorized . Has there been any changes in server code that caused this ?
client = DatabaseClientFactory.newClient("localhost", restPort, dbName,"rest-admin","x",Authentication.BASIC);
C. On changing the Authentication to DIGEST, I get "com.marklogic.client.FailedRequestException: Local message: failed to apply resource at eval: Internal Server Error. Server Message: SEC-PRIV: Need privilege: http://marklogic.com/xdmp/privileges/xdmp-eval-in . See the MarkLogic server error log for further detail."

client = DatabaseClientFactory.newClient("localhost", restPort, dbName,"rest-admin","x",Authentication.DIGEST);

D. Nevertheless, using client object created with incorrect credentials to perform eval() causes NPE.

	@Test(expected=FailedRequestException.class)
	public void testRuntimeDBclientWithNoPrivUser() throws KeyManagementException, NoSuchAlgorithmException, Exception {
		int restPort = getRestServerPort();
		if 	(IsSecurityEnabled()) throw new FailedRequestException("Illegal");
		else
			client = DatabaseClientFactory.newClient("localhost", restPort, dbName,"rest-admin","x",Authentication.BASIC);
		String insertJSON = "xdmp:document-insert(\"test2.json\",object-node {\"test\":\"hello\"})";
		client.newServerEval().xquery(insertJSON).eval();
		String query1 = "fn:count(fn:doc())";
		int response = client.newServerEval().xquery(query1).eval().next().getNumber().intValue();
		assertEquals("count of documents ",1,response);
		String query2 ="declareUpdate();xdmp.documentDelete(\"test2.json\");";
		client.newServerEval().javascript(query2).eval();
		int response2 = client.newServerEval().xquery(query1).eval().next().getNumber().intValue();
		assertEquals("count of documents ",0,response2);
		client.release();
		
	}
java.lang.NullPointerException
	at com.marklogic.client.impl.JerseyServices.checkStatus(JerseyServices.java:4271)
	at com.marklogic.client.impl.JerseyServices.postIteratedResourceImpl(JerseyServices.java:3745)
	at com.marklogic.client.impl.JerseyServices.postEvalInvoke(JerseyServices.java:3688)
	at com.marklogic.client.impl.ServerEvaluationCallImpl.eval(ServerEvaluationCallImpl.java:164)
	at com.marklogic.client.functionaltest.TestRuntimeDBselection.test(TestRuntimeDBselection.java:126)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)


@srinathgit srinathgit added this to the java-client-api-4.0-ea4 milestone Dec 6, 2016
@srinathgit srinathgit changed the title NullPointerException thrown while doing eval() with client object created with incorrect credentials REGR:NullPointerException thrown while doing eval() with client object created with incorrect credentials Dec 6, 2016
@sammefford sammefford added fix and removed new labels Dec 6, 2016
@sammefford sammefford assigned srinathgit and unassigned sammefford Dec 6, 2016
@sammefford sammefford added test and removed fix labels Dec 6, 2016
@sammefford
Copy link
Contributor

Please test the fix on branch issue582

@srinathgit
Copy link
Contributor Author

Issue is fixed on branch issue582

@srinathgit srinathgit added ship and removed test labels Dec 6, 2016
srinathgit added a commit that referenced this issue Dec 6, 2016
@sammefford sammefford assigned sammefford and unassigned srinathgit Dec 7, 2016
@sammefford
Copy link
Contributor

I'll move the fix to develop once I get review and approval

@sammefford
Copy link
Contributor

Ok, the change is now in develop

@srinathgit
Copy link
Contributor Author

Test runs fine in develop branch

@srinathgit srinathgit added ship and removed test labels Dec 8, 2016
@jmakeig jmakeig closed this as completed Sep 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants