Skip to content

Commit c797644

Browse files
committed
Update TestRecordFactoryInputStream.java
1 parent 811eb4a commit c797644

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

poi/src/test/java/org/apache/poi/hssf/record/TestRecordFactoryInputStream.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,22 @@ void suppliedPasswordOK() {
133133
+ SAMPLE_WINDOW1_ENCR2
134134
);
135135

136+
RecordFactoryInputStream rfis = createRFIS(dataCorrectDefault, "passw0rd");
137+
confirmReadInitialRecords(rfis);
138+
}
139+
140+
@Test
141+
void suppliedPasswordOKBiff8EncryptionKey() {
142+
// This encoding depends on docId, password and stream position
143+
final String SAMPLE_WINDOW1_ENCR2 = "3D 00 12 00"
144+
+ "45, B9, 90, FE, B6, C6, EC, 73, EE, 3F, 52, 45, 97, DB, E3, C1, D6, FE";
145+
146+
byte[] dataCorrectDefault = HexRead.readFromString(""
147+
+ COMMON_HEX_DATA
148+
+ "C728659A C38E35E0 568A338F C3FC9D70" // correct saltHash for supplied password (and docId/saltHash)
149+
+ SAMPLE_WINDOW1_ENCR2
150+
);
151+
136152
Biff8EncryptionKey.setCurrentUserPassword("passw0rd");
137153
try {
138154
RecordFactoryInputStream rfis = createRFIS(dataCorrectDefault);
@@ -142,7 +158,6 @@ void suppliedPasswordOK() {
142158
}
143159
}
144160

145-
146161
/**
147162
* makes sure the record stream starts with {@link BOFRecord}, {@link FilePassRecord} and then {@link WindowOneRecord}
148163
* The third record is decrypted so this method also checks its content.
@@ -157,4 +172,11 @@ private void confirmReadInitialRecords(RecordFactoryInputStream rfis) {
157172
private static RecordFactoryInputStream createRFIS(byte[] data) {
158173
return new RecordFactoryInputStream(new ByteArrayInputStream(data), true);
159174
}
175+
176+
private static RecordFactoryInputStream createRFIS(byte[] data, String password) {
177+
return new RecordFactoryInputStream(
178+
new ByteArrayInputStream(data),
179+
true,
180+
password.toCharArray());
181+
}
160182
}

0 commit comments

Comments
 (0)