Project

General

Profile

« Previous | Next » 

Revision 5375

Added by berkley over 14 years ago

added a test for access control changes

View differences:

test/edu/ucsb/nceas/metacat/dataone/CrudServiceTest.java
92 92
		suite.addTest(new CrudServiceTest("testGetSystemMetadata"));
93 93
		suite.addTest(new CrudServiceTest("testUpdate"));
94 94
		suite.addTest(new CrudServiceTest("testListObjects"));
95
		suite.addTest(new CrudServiceTest("testAccessControl"));
95 96
		//suite.addTest(new CrudServiceTest(""));
96 97
		return suite;
97 98
	}
98 99
	
99 100
	/**
101
	 * make sure that only valid sessions can update/delete
102
	 */
103
	public void testAccessControl()
104
	{
105
        try
106
        {
107
            CrudService cs = CrudService.getInstance();
108
            AuthToken token = getToken();
109
            //create a doc
110
            Identifier id = createDoc(token, getTestDoc());
111
            
112
            //get the doc and sysmetadata
113
            String gotDoc = getDoc(token, id);
114
            SystemMetadata sm = getSystemMetadata(token, id);
115
            
116
            //break the session id
117
            String sessionid = "somefakesessionid";
118
            token = new AuthToken(sessionid);
119
            
120
            //update the doc
121
            gotDoc = gotDoc.replaceAll("XXX", "YYY");
122
            Identifier newid = new Identifier();
123
            newid.setValue(generateDocumentId());
124
            StringBufferInputStream sbis = new StringBufferInputStream(gotDoc);
125
            SystemMetadata newsm = createSystemMetadata(newid, gotDoc);
126
            Identifier updatedid = cs.update(token, newid, sbis, id, newsm);
127
            fail("exception should have been thrown.");
128
        }
129
        catch(Exception e)
130
        {
131
            //System.out.println("Exception in testCreateAndGet (this *should* happen): " + e.getMessage());
132
        }
133
	}
134
	
135
	/**
100 136
	 * public ObjectList listObjects(AuthToken token, Date startTime, Date endTime, 
101 137
     *     ObjectFormat objectFormat, boolean replicaStatus, int start, int count)
102 138
     *       throws NotAuthorized, InvalidRequest, NotImplemented, ServiceFailure, InvalidToken

Also available in: Unified diff