def test_subdomain_reserve_paid_over_limit(self, client, current_user, session): """User can't reserve more than 5 subdomains if they are paid tier""" sub1 = subdomain.ReservedSubdomainFactory(user=current_user, name="sub") sub2 = subdomain.ReservedSubdomainFactory(user=current_user, name="subtract") sub3 = subdomain.ReservedSubdomainFactory(user=current_user, name="subwoofer") sub4 = subdomain.ReservedSubdomainFactory(user=current_user, name="subconscious") sub5 = subdomain.ReservedSubdomainFactory(user=current_user, name="subreddit") session.add(sub1) session.add(sub2) session.add(sub3) session.add(sub4) session.add(sub5) session.flush() res = client.post( "/subdomains", json={ "data": { "type": "subdomain", "attributes": { "name": "test" } } }, ) assert res.status_code == 403
def test_subdomain_filter(self, client, session, current_user): """Can filter a subdomain using JSON-API compliant filters""" sub1 = subdomain.ReservedSubdomainFactory(user=current_user, name="submarine") sub2 = subdomain.ReservedSubdomainFactory(user=current_user, name="sublime") session.add(sub1, sub2) session.flush() res = client.get(f"/subdomains?filter[name]=submarine") assert_valid_schema(res.get_json(), "subdomains.json") assert str(sub1.id) in values(res.get_json(), "data/*/id") assert str(sub2.id) not in values(res.get_json(), "data/*/id")
def test_tunnel_index(self, admin_client, current_user, session): """User can list all of their tunnels""" sub = subdomain.ReservedSubdomainFactory( user=current_user, name="testtunnelsubdomain" ) session.add(sub) session.flush() tun = TunnelCreationService( current_user, sub.id, ["http"], "i-am-a-lousy-key" ).create() session.add(tun) session.flush() res = admin_client.post( "/admin/tunnels", json={ "data": { "type": "tunnel", "attributes": { "subdomainName": "testtunnelsubdomain", "reason": "testing", }, } }, ) assert res.status_code == 204
def test_tunnel_open_with_subdomain(self, client, current_user, session): """User can open a tunnel when providing a subdomain they own""" sub = subdomain.ReservedSubdomainFactory(user=current_user, name="testtunnelsubdomain") session.add(sub) session.flush() res = client.post( "/tunnels", json={ "data": { "type": "tunnel", "attributes": { "port": ["http"], "sshKey": "i-am-a-lousy-public-key", }, "relationships": { "subdomain": { "data": { "type": "subdomain", "id": str(sub.id) } } }, } }, ) assert res.status_code == 201 assert len(values(res.get_json(), "data/id")) == 1 assert_valid_schema(res.get_data(), "tunnel.json") assert Tunnel.query.filter_by(user=current_user).count() == 1
def test_tunnel_open_unowned_subdomain(self, client, current_user, session): """User can not open a tunnel if they dont own the subdomain""" sub = subdomain.ReservedSubdomainFactory( name="unowndedsubdomaintunnel") session.add(sub) session.flush() res = client.post( "/tunnels", json={ "data": { "type": "tunnel", "attributes": { "port": ["http"], "sshKey": "i-am-a-lousy-key" }, "relationships": { "subdomain": { "data": { "type": "subdomain", "id": str(sub.id) } } }, } }, ) assert res.status_code == 403 assert Tunnel.query.filter_by(user=current_user).count() == 0
def test_subdomain_release_owned(self, client, current_user): """User can release a subdomain they own""" sub = subdomain.ReservedSubdomainFactory(user=current_user, name="domainiown") res = client.delete(f"/subdomains/{sub.id}") assert res.status_code == 204
def test_subdomain_release_unowned(self, client, session): """User cant release a subdomain is owned by someone else""" sub = subdomain.ReservedSubdomainFactory(name="domainyouown") session.add(sub) session.flush() res = client.delete(f"/subdomains/{sub.id}") assert res.status_code == 404
def test_tunnel_filter_by_subdomain_name(self, client, session, current_user): """Can filter a subdomain using JSON-API compliant filters""" sub1 = subdomain.ReservedSubdomainFactory(user=current_user, name="sub-sandwich") sub2 = subdomain.ReservedSubdomainFactory(user=current_user, name="subscription") tun1 = tunnel.TunnelFactory(subdomain=sub1) tun2 = tunnel.TunnelFactory(subdomain=sub2) session.add(tun1, tun2) session.flush() res = client.get(f"/tunnels?filter[subdomain][name]=sub-sandwich") assert_valid_schema(res.get_json(), "tunnels.json") assert str(tun1.id) in values(res.get_json(), "data/*/id") assert str(tun2.id) not in values(res.get_json(), "data/*/id")
def test_tunnel_close_owned(self, client, session, current_user): """User can close a tunnel""" sub = subdomain.ReservedSubdomainFactory(user=current_user, name="testtunnelsubdomain") session.add(sub) session.flush() tun = TunnelCreationService(current_user, sub.id, ["http"], "i-am-a-lousy-key").create() session.add(tun) session.flush() res = client.delete("/tunnels/" + str(tun.id)) assert res.status_code == 204
def test_account_delete_account_with_reserved_subdomains( self, client, current_user, session ): """DELETE to /account url succeeds and associated reserved subdomains no longer exists""" sub1 = subdomain.ReservedSubdomainFactory(user=current_user, name="sub-bass") session.add(sub1) session.flush() assert Subdomain.query.filter_by(id=sub1.id).first() is not None res = client.delete( "/account", json={"data": {"type": "user", "attributes": {"password": "******"}}}, ) assert res.status_code is 200 assert User.query.filter_by(uuid=current_user.uuid).first() is None assert Subdomain.query.filter_by(id=sub1.id).first() is None
def test_subdomain_reserve_owned(self, client, current_user, session): """User cant reserve an already reserved subdomain""" sub = subdomain.ReservedSubdomainFactory(name="substation") session.add(sub) session.flush() res = client.post( "/subdomains", json={ "data": { "type": "subdomain", "attributes": { "name": "substation" } } }, ) assert res.status_code == 400 assert (res.json["data"]["attributes"]["detail"] == "Subdomain has already been reserved")