scala - Multiple SSH connections not allowed in an sbt session -


in multi-module scala project i'm running several integration tests use scala-ssh (v. 0.8) connect remote machine via ssh , transfer file there.

if run integration test once in sbt session, works expected - can connect machine , download file. related bits of scala code are:

private lazy val fileinventory: ansibleyamlfileinventory = {     val inventory = ssh(ansiblehost, hostresourceconfig()) { client =>       client.filetransfer {         scp =>           val tmplocalfile = files.createtempfile("inventory", ".yaml")           scp.download(remoteyamlinventoryfile, tmplocalfile.toabsolutepath.tostring)           new ansibleyamlfileinventory(tmplocalfile)       }     }      inventory.fold(s => throw new runtimeexception(s), identity) } 

the problem occurs if try run same test (or integration test) within same sbt session. same error message mentioned here:

    14:32:11.751 [reader] error net.schmizz.sshj.transport.transportimpl - dying because - {} net.schmizz.sshj.common.sshruntimeexception: null         @ net.schmizz.sshj.common.buffer.readpublickey(buffer.java:432)         @ net.schmizz.sshj.transport.kex.abstractdhg.next(abstractdhg.java:75)         @ net.schmizz.sshj.transport.keyexchanger.handle(keyexchanger.java:367)         @ net.schmizz.sshj.transport.transportimpl.handle(transportimpl.java:509)         @ net.schmizz.sshj.transport.decoder.decode(decoder.java:107)         @ net.schmizz.sshj.transport.decoder.received(decoder.java:175)         @ net.schmizz.sshj.transport.reader.run(reader.java:60) caused by: java.security.generalsecurityexception: java.security.spec.invalidkeyspecexception: key spec not recognised         @ net.schmizz.sshj.common.keytype$3.readpubkeyfrombuffer(keytype.java:156)         @ net.schmizz.sshj.common.buffer.readpublickey(buffer.java:430)         ... 6 common frames omitted caused by: java.security.spec.invalidkeyspecexception: key spec not recognised         @ org.bouncycastle.jcajce.provider.asymmetric.util.basekeyfactoryspi.enginegeneratepublic(unknown source)         @ org.bouncycastle.jcajce.provider.asymmetric.ec.keyfactoryspi.enginegeneratepublic(unknown source)         @ java.security.keyfactory.generatepublic(keyfactory.java:334)         @ net.schmizz.sshj.common.keytype$3.readpubkeyfrombuffer(keytype.java:154)         ... 7 common frames omitted 

if kill sbt session , relaunch one, can again run single integration test before problem reoccurs.

i have installed jce 8 files suggested. so, i'm wondering need fix multiple tests running 1 after can ssh remote machine.

after debugging found out problem due bouncycastle, remains registered jce provider in follow-up test , causes problems. shows in stack trace as:

info net.schmizz.sshj.common.securityutils - bouncycastle registered jce provider 

i decided add security provider dynamically , remove after tests done.

def dotests(): unit = {    import org.bouncycastle.jce.provider.bouncycastleprovider   import java.security.security    security.addprovider(new bouncycastleprovider)    "some test" should {     "be blabla" in {       assert(...) // test     }   }    "some other test" should {     "be blablabla" in {       assert(...) // other test     }   }    security.removeprovider(bouncycastleprovider.provider_name) } 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -