Project

General

Profile

« Previous | Next » 

Revision 9267

Added by Jing Tao over 9 years ago

Add the code to test that non-cn session can't call some methods like registerSystemMetadata, updateSystemMetadata and et al.

View differences:

test/edu/ucsb/nceas/metacat/dataone/CNodeServiceTest.java
128 128
	    printTestHeader("testRegisterSystemMetadata");
129 129

  
130 130
	    try {
131
	        Session testSession = getTestSession();
131 132
            Session session = getCNSession();
132 133
			Identifier guid = new Identifier();
133 134
			guid.setValue("testRegisterSystemMetadata." + System.currentTimeMillis());
134 135
			InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
135 136
			SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
137
			try {
138
			    CNodeService.getInstance(request).registerSystemMetadata(testSession, guid, sysmeta);
139
			    fail("We shouldn't get there since the test session can't regsiter system metadata");
140
			} catch (NotAuthorized ee) {
141
			    
142
			}
136 143
			Identifier retGuid = CNodeService.getInstance(request).registerSystemMetadata(session, guid, sysmeta);
137 144
			assertEquals(guid.getValue(), retGuid.getValue());
138 145
			return retGuid;
......
451 458
			// set it
452 459
			ReplicationStatus status = ReplicationStatus.COMPLETED;
453 460
			BaseException failure = new NotAuthorized("000", "Mock exception for " + this.getClass().getName());
461
			//Test the failure of setReplicationStatus by a non-cn subject
462
			Session testSession = getTestSession();
463
			try {
464
			    CNodeService.getInstance(request).setReplicationStatus(testSession, guid, replicaMemberNode, status, failure);
465
			    fail("It can't reach here since the non-cn subject can't call setReplicationStatus");
466
			} catch (NotAuthorized ee) {
467
			    
468
			}
469
			//Test the success of setReplicationStatus by a cn subject
454 470
			boolean result = CNodeService.getInstance(request).setReplicationStatus(session, guid, replicaMemberNode, status, failure);
455 471
			assertTrue(result);
456 472
			// get it
......
1179 1195
          System.out.println("the checksum from request is "+metadata.getChecksum().getValue());
1180 1196
          assertTrue(metadata.getSize().equals(sysmeta.getSize()));
1181 1197
          
1198
          //test to fail to update system metadata by a non-cn subject
1199
          Session testSession = getTestSession();
1200
          metadata.setArchived(true);
1201
          try {
1202
              CNodeService.getInstance(request).updateSystemMetadata(testSession, guid, metadata);
1203
              fail("It shouldn't get there since the test session can't update system metadata");
1204
          } catch (NotAuthorized e) {
1205
              
1206
          }
1207
         
1208
          
1182 1209
          //update system metadata sucessfully
1183 1210
          metadata.setArchived(true);
1184 1211
          CNodeService.getInstance(request).updateSystemMetadata(session, guid, metadata);

Also available in: Unified diff