Esempio n. 1
0
  def testThreat(self):
    iteps = [ThreatEnvironmentProperties(self.iThreats[0]["theEnvironmentProperties"][0]["theName"],self.iThreats[0]["theEnvironmentProperties"][0]["theLikelihood"],self.iThreats[0]["theEnvironmentProperties"][0]["theAssets"],self.iThreats[0]["theEnvironmentProperties"][0]["theAttackers"],self.iThreats[0]["theEnvironmentProperties"][0]["theProperties"][0][1],self.iThreats[0]["theEnvironmentProperties"][0]["theProperties"][0][1])]
    itps = ThreatParameters(self.iThreats[0]["theName"],self.iThreats[0]["theType"],self.iThreats[0]["theMethod"],[],iteps)
    b = Borg()
    b.dbProxy.addThreat(itps)
    oThreats = b.dbProxy.getThreats()
    o = oThreats[self.iThreats[0]["theName"]]
    self.assertEqual(itps.name(), o.name())
    self.assertEqual(itps.type(),o.type())
    self.assertEqual(itps.method(),o.method())
    oteps = o.environmentProperties()
    self.assertEqual(iteps[0].name(), oteps[0].name())
    self.assertEqual(iteps[0].likelihood()[0], oteps[0].likelihood()[0])
    self.assertEqual(str(iteps[0].assets()[0]), str(oteps[0].assets()[0]))
    self.assertEqual(str(iteps[0].attackers()[0]), str(oteps[0].attackers()[0]))
    self.assertEqual(str(iteps[0].rationale()[0]), str(oteps[0].rationale()[0]))

    itps.theName = 'Updated threat'
    itps.setId(o.id())
    b.dbProxy.updateThreat(itps)
    oThreats = b.dbProxy.getThreats()
    o = oThreats['Updated threat']
    self.assertEqual(o.name(),'Updated threat')


    b.dbProxy.deleteThreat(o.id())
Esempio n. 2
0
  def testThreat(self):
    iteps = [ThreatEnvironmentProperties(self.iThreats[0]["theEnvironmentProperties"][0]["theName"],self.iThreats[0]["theEnvironmentProperties"][0]["theLikelihood"],self.iThreats[0]["theEnvironmentProperties"][0]["theAssets"],self.iThreats[0]["theEnvironmentProperties"][0]["theAttackers"],self.iThreats[0]["theEnvironmentProperties"][0]["theProperties"][0][1],self.iThreats[0]["theEnvironmentProperties"][0]["theProperties"][0][1]),ThreatEnvironmentProperties(self.iThreats[0]["theEnvironmentProperties"][1]["theName"],self.iThreats[0]["theEnvironmentProperties"][1]["theLikelihood"],self.iThreats[0]["theEnvironmentProperties"][1]["theAssets"],self.iThreats[0]["theEnvironmentProperties"][1]["theAttackers"],self.iThreats[0]["theEnvironmentProperties"][1]["theProperties"][0][1],self.iThreats[0]["theEnvironmentProperties"][1]["theProperties"][0][1])]
    itps = ThreatParameters(self.iThreats[0]["theName"],self.iThreats[0]["theType"],self.iThreats[0]["theMethod"],[],iteps)
    b = Borg()
    b.dbProxy.addThreat(itps)
    oThreats = b.dbProxy.getThreats()
    o = oThreats[self.iThreats[0]["theName"]]
    self.assertEqual(itps.name(), o.name())
    self.assertEqual(itps.type(),o.type())
    self.assertEqual(itps.method(),o.method())
    oteps = o.environmentProperties()
    self.assertEqual(iteps[0].name(), oteps[0].name())

    self.assertEqual(iteps[0].likelihood(), oteps[0].likelihood())
    self.assertEqual(iteps[0].likelihood(),o.likelihood('Day','Maximise','None'))
    self.assertEqual(iteps[0].likelihood(),o.likelihood('','Maximise','None'))
    self.assertEqual(iteps[0].likelihood(),o.likelihood('','Override','Day'))
    self.assertEqual(iteps[0].assets(), oteps[0].assets())
    self.assertEqual(iteps[0].assets(), o.assets('Day',''))
    self.assertEqual(iteps[0].assets(), list(o.assets('','Maximise')))
    self.assertEqual(iteps[0].attackers(), oteps[0].attackers())
    self.assertEqual(iteps[0].attackers(), o.attackers('Day',''))
    self.assertEqual(iteps[0].attackers(), list(o.attackers('','Maximise')))
    self.assertEqual(str(iteps[0].rationale()[0]), oteps[0].rationale()[0])
    self.assertEqual(str(iteps[0].rationale()[1]), oteps[0].rationale()[1])
    self.assertEqual(str(iteps[0].rationale()[2]), oteps[0].rationale()[2])
    self.assertEqual(str(iteps[0].rationale()[3]), oteps[0].rationale()[3])
    self.assertEqual(str(iteps[0].rationale()[4]), oteps[0].rationale()[4])
    self.assertEqual(str(iteps[0].rationale()[5]), oteps[0].rationale()[5])
    self.assertEqual(str(iteps[0].rationale()[6]), oteps[0].rationale()[6])
    self.assertEqual(str(iteps[0].rationale()[7]), oteps[0].rationale()[7])
    self.assertEqual(array([0,2,0,0,0,0,0,0]).tolist(),o.securityProperties('','Maximise','').tolist())
    self.assertEqual(array([0,2,0,0,0,0,0,0]).tolist(),o.securityProperties('','Override','Day').tolist())
    self.assertEqual([['Integrity','Medium']],o.propertyList('','Maximise',''))
    self.assertEqual([['Integrity','Medium']],o.propertyList('','Override','Day'))

    envName = self.iThreats[0]["theEnvironmentProperties"][0]["theName"]
    self.assertEqual(iteps[0].likelihood(), o.likelihood(envName,'',envName))
    self.assertEqual(iteps[0].assets(), o.assets(envName,''))
    self.assertEqual(iteps[0].attackers(), o.attackers(envName,''))


    itps.theName = 'Updated threat'
    itps.setId(o.id())
    b.dbProxy.updateThreat(itps)
    oThreats = b.dbProxy.getThreats()
    o = oThreats['Updated threat']
    self.assertEqual(o.name(),'Updated threat')


    b.dbProxy.deleteThreat(o.id())
Esempio n. 3
0
  def testThreat(self):
    iteps = [ThreatEnvironmentProperties(self.iThreats[0]["theEnvironmentProperties"][0]["theName"],self.iThreats[0]["theEnvironmentProperties"][0]["theLikelihood"],self.iThreats[0]["theEnvironmentProperties"][0]["theAssets"],self.iThreats[0]["theEnvironmentProperties"][0]["theAttackers"],self.iThreats[0]["theEnvironmentProperties"][0]["theProperties"][0][1],self.iThreats[0]["theEnvironmentProperties"][0]["theProperties"][0][1])]
    itps = ThreatParameters(self.iThreats[0]["theName"],self.iThreats[0]["theType"],self.iThreats[0]["theMethod"],[],iteps)
    b = Borg()
    b.dbProxy.addThreat(itps)
    oThreats = b.dbProxy.getThreats()
    o = oThreats[self.iThreats[0]["theName"]]
    self.assertEqual(itps.name(), o.name())
    self.assertEqual(itps.type(),o.type())
    self.assertEqual(itps.method(),o.method())
    oteps = o.environmentProperties()
    self.assertEqual(iteps[0].name(), oteps[0].name())

    self.assertEqual(iteps[0].likelihood()[0], oteps[0].likelihood()[0])
    self.assertEqual(iteps[0].assets(), oteps[0].assets())
    self.assertEqual(iteps[0].attackers(), oteps[0].attackers())
    self.assertEqual(str(iteps[0].rationale()[0]), oteps[0].rationale()[0])
    self.assertEqual(str(iteps[0].rationale()[1]), oteps[0].rationale()[1])
    self.assertEqual(str(iteps[0].rationale()[2]), oteps[0].rationale()[2])
    self.assertEqual(str(iteps[0].rationale()[3]), oteps[0].rationale()[3])
    self.assertEqual(str(iteps[0].rationale()[4]), oteps[0].rationale()[4])
    self.assertEqual(str(iteps[0].rationale()[5]), oteps[0].rationale()[5])
    self.assertEqual(str(iteps[0].rationale()[6]), oteps[0].rationale()[6])
    self.assertEqual(str(iteps[0].rationale()[7]), oteps[0].rationale()[7])

    envName = self.iThreats[0]["theEnvironmentProperties"][0]["theName"]
    self.assertEqual(iteps[0].likelihood(), o.likelihood(envName,'',envName))
    self.assertEqual(iteps[0].assets(), o.assets(envName,''))
    self.assertEqual(iteps[0].attackers(), o.attackers(envName,''))


    itps.theName = 'Updated threat'
    itps.setId(o.id())
    b.dbProxy.updateThreat(itps)
    oThreats = b.dbProxy.getThreats()
    o = oThreats['Updated threat']
    self.assertEqual(o.name(),'Updated threat')


    b.dbProxy.deleteThreat(o.id())
Esempio n. 4
0
    def testThreat(self):
        iteps = [
            ThreatEnvironmentProperties(
                self.iThreats[0]["theEnvironmentProperties"][0]["theName"],
                self.iThreats[0]["theEnvironmentProperties"][0]
                ["theLikelihood"],
                self.iThreats[0]["theEnvironmentProperties"][0]["theAssets"],
                self.iThreats[0]["theEnvironmentProperties"][0]
                ["theAttackers"], self.iThreats[0]["theEnvironmentProperties"]
                [0]["theProperties"][0][1], self.iThreats[0]
                ["theEnvironmentProperties"][0]["theProperties"][0][1]),
            ThreatEnvironmentProperties(
                self.iThreats[0]["theEnvironmentProperties"][1]["theName"],
                self.iThreats[0]["theEnvironmentProperties"][1]
                ["theLikelihood"],
                self.iThreats[0]["theEnvironmentProperties"][1]["theAssets"],
                self.iThreats[0]["theEnvironmentProperties"][1]
                ["theAttackers"], self.iThreats[0]["theEnvironmentProperties"]
                [1]["theProperties"][0][1], self.iThreats[0]
                ["theEnvironmentProperties"][1]["theProperties"][0][1])
        ]
        itps = ThreatParameters(self.iThreats[0]["theName"],
                                self.iThreats[0]["theType"],
                                self.iThreats[0]["theMethod"], [], iteps)
        b = Borg()
        b.dbProxy.addThreat(itps)
        oThreats = b.dbProxy.getThreats()
        o = oThreats[self.iThreats[0]["theName"]]
        self.assertEqual(itps.name(), o.name())
        self.assertEqual(itps.type(), o.type())
        self.assertEqual(itps.method(), o.method())
        oteps = o.environmentProperties()
        self.assertEqual(iteps[0].name(), oteps[0].name())

        self.assertEqual(iteps[0].likelihood(), oteps[0].likelihood())
        self.assertEqual(iteps[0].likelihood(),
                         o.likelihood('Day', 'Maximise', 'None'))
        self.assertEqual(iteps[0].likelihood(),
                         o.likelihood('', 'Maximise', 'None'))
        self.assertEqual(iteps[0].likelihood(),
                         o.likelihood('', 'Override', 'Day'))
        self.assertEqual(iteps[0].assets(), oteps[0].assets())
        self.assertEqual(iteps[0].assets(), o.assets('Day', ''))
        self.assertEqual(iteps[0].assets(), list(o.assets('', 'Maximise')))
        self.assertEqual(iteps[0].attackers(), oteps[0].attackers())
        self.assertEqual(iteps[0].attackers(), o.attackers('Day', ''))
        self.assertEqual(iteps[0].attackers(),
                         list(o.attackers('', 'Maximise')))
        self.assertEqual(str(iteps[0].rationale()[0]), oteps[0].rationale()[0])
        self.assertEqual(str(iteps[0].rationale()[1]), oteps[0].rationale()[1])
        self.assertEqual(str(iteps[0].rationale()[2]), oteps[0].rationale()[2])
        self.assertEqual(str(iteps[0].rationale()[3]), oteps[0].rationale()[3])
        self.assertEqual(str(iteps[0].rationale()[4]), oteps[0].rationale()[4])
        self.assertEqual(str(iteps[0].rationale()[5]), oteps[0].rationale()[5])
        self.assertEqual(str(iteps[0].rationale()[6]), oteps[0].rationale()[6])
        self.assertEqual(str(iteps[0].rationale()[7]), oteps[0].rationale()[7])
        self.assertEqual(
            array([0, 2, 0, 0, 0, 0, 0, 0]).tolist(),
            o.securityProperties('', 'Maximise', '').tolist())
        self.assertEqual(
            array([0, 2, 0, 0, 0, 0, 0, 0]).tolist(),
            o.securityProperties('', 'Override', 'Day').tolist())
        self.assertEqual([['Integrity', 'Medium']],
                         o.propertyList('', 'Maximise', ''))
        self.assertEqual([['Integrity', 'Medium']],
                         o.propertyList('', 'Override', 'Day'))

        envName = self.iThreats[0]["theEnvironmentProperties"][0]["theName"]
        self.assertEqual(iteps[0].likelihood(),
                         o.likelihood(envName, '', envName))
        self.assertEqual(iteps[0].assets(), o.assets(envName, ''))
        self.assertEqual(iteps[0].attackers(), o.attackers(envName, ''))

        itps.theName = 'Updated threat'
        itps.setId(o.id())
        b.dbProxy.updateThreat(itps)
        oThreats = b.dbProxy.getThreats()
        o = oThreats['Updated threat']
        self.assertEqual(o.name(), 'Updated threat')

        b.dbProxy.deleteThreat(o.id())