File size: 1,850 Bytes
5ca3c16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""The website is chosen by each request while the Java safety frame is fixed."""
import unittest
from src.modules.execution.scenarios import webapp
from src.modules.harness.policy import Harness
from src.modules.skill.domain.models import SkillError
from src.modules.skill.packs.examples import framework_candidate


class WebappRequirementTests(unittest.TestCase):
    def setUp(self):
        self.profile=framework_candidate().model_copy(update={
            'profile_id':webapp.PROFILE,'allowed_paths':['src/main/','website/'],'state':'approved'}).model_dump()
        self.harness=Harness(enabled=True,allow_qemu=True)

    def test_different_business_pages_keep_same_framework_without_calculator_source(self):
        pages=[
            '<!doctype html><html><style>button{color:red}</style><button>扫雷</button><script>let mines=10;</script></html>',
            '<!doctype html><html><style>button{color:blue}</style><button>翻牌配对</button><script>let pairs=8;</script></html>',
        ]
        sources=[self.harness.files(webapp.prepare_patch({'files':{webapp.PAGE:page}}),self.profile) for page in pages]
        self.assertNotEqual(sources[0]['source_digest'],sources[1]['source_digest'])
        self.assertEqual(sources[0]['files'][webapp.JAVA],sources[1]['files'][webapp.JAVA])
        self.assertEqual([s['files'][webapp.PAGE] for s in sources],pages)

    def test_model_cannot_change_java_or_request_network_page(self):
        with self.assertRaises(SkillError):
            webapp.prepare_patch({'files':{webapp.PAGE:'<html></html>',webapp.JAVA:'bad'}})
        page='<html><style>x{}</style><script>fetch("/api/admin")</script></html>'
        with self.assertRaises(SkillError):
            self.harness.files(webapp.prepare_patch({'files':{webapp.PAGE:page}}),self.profile)


if __name__=='__main__':unittest.main()