Skip to content

Commit

Permalink
Correctly clone values provided by the setter
Browse files Browse the repository at this point in the history
Fixes #1437
  • Loading branch information
marci4 committed Oct 8, 2024
1 parent 4aef466 commit a566891
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,11 @@ public String getProvidedExtensionAsServer() {

@Override
public IExtension copyInstance() {
return new PerMessageDeflateExtension();
PerMessageDeflateExtension clone = new PerMessageDeflateExtension();
clone.setThreshold(this.getThreshold());
clone.setClientNoContextTakeover(this.isClientNoContextTakeover());
clone.setServerNoContextTakeover(this.isServerNoContextTakeover());
return clone;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,36 @@ public void testSetClientNoContextTakeover() {
@Test
public void testCopyInstance() {
PerMessageDeflateExtension deflateExtension = new PerMessageDeflateExtension();
IExtension newDeflateExtension = deflateExtension.copyInstance();
assertEquals(deflateExtension.toString(), newDeflateExtension.toString());
PerMessageDeflateExtension newDeflateExtension = (PerMessageDeflateExtension)deflateExtension.copyInstance();
assertEquals("PerMessageDeflateExtension", newDeflateExtension.toString());
// Also check the values
assertEquals(deflateExtension.getThreshold(), newDeflateExtension.getThreshold());
assertEquals(deflateExtension.isClientNoContextTakeover(), newDeflateExtension.isClientNoContextTakeover());
assertEquals(deflateExtension.isServerNoContextTakeover(), newDeflateExtension.isServerNoContextTakeover());
// Adjust this to the factory
//assertEquals(deflateExtension.getDeflater(), newDeflateExtension.getDeflater());
//assertEquals(deflateExtension.getInflater(), newDeflateExtension.getInflater());

deflateExtension = new PerMessageDeflateExtension();
deflateExtension.setThreshold(512);
deflateExtension.setServerNoContextTakeover(false);
deflateExtension.setClientNoContextTakeover(true);
newDeflateExtension = (PerMessageDeflateExtension)deflateExtension.copyInstance();

assertEquals(deflateExtension.getThreshold(), newDeflateExtension.getThreshold());
assertEquals(deflateExtension.isClientNoContextTakeover(), newDeflateExtension.isClientNoContextTakeover());
assertEquals(deflateExtension.isServerNoContextTakeover(), newDeflateExtension.isServerNoContextTakeover());


deflateExtension = new PerMessageDeflateExtension();
deflateExtension.setThreshold(64);
deflateExtension.setServerNoContextTakeover(true);
deflateExtension.setClientNoContextTakeover(false);
newDeflateExtension = (PerMessageDeflateExtension)deflateExtension.copyInstance();

assertEquals(deflateExtension.getThreshold(), newDeflateExtension.getThreshold());
assertEquals(deflateExtension.isClientNoContextTakeover(), newDeflateExtension.isClientNoContextTakeover());
assertEquals(deflateExtension.isServerNoContextTakeover(), newDeflateExtension.isServerNoContextTakeover());
}

@Test
Expand Down Expand Up @@ -222,4 +250,11 @@ public void testSetDeflater() {
assertEquals(deflateExtension.getDeflater().finished(),
new Deflater(Deflater.DEFAULT_COMPRESSION, false).finished());
}
@Test
public void testDefaults() {
PerMessageDeflateExtension deflateExtension = new PerMessageDeflateExtension();
assertFalse(deflateExtension.isClientNoContextTakeover());
assertTrue(deflateExtension.isServerNoContextTakeover());
assertEquals(1024, deflateExtension.getThreshold());
}
}

0 comments on commit a566891

Please sign in to comment.