Skip to content

Commit

Permalink
Make sure ASN0 measurement are hidden
Browse files Browse the repository at this point in the history
* Allow only valid ASN values in search filters

* Drop search results with AS0 in probe_asn

* Do no show measurements with AS0 in report_id

* Fix formatting of long text in msmt 404 page

See #495
  • Loading branch information
sarathms authored and bassosimone committed Oct 7, 2020
1 parent 99fa5ad commit 02a32db
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 13 deletions.
4 changes: 1 addition & 3 deletions components/measurement/MeasurementContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import PsiphonDetails from './nettests/Psiphon'
import TorDetails from './nettests/Tor'

import DefaultTestDetails from './nettests/Default'
import MeasurementNotFound from './MeasurementNotFound'

const mapTestDetails = {
web_connectivity: WebConnectivityDetails,
Expand All @@ -30,9 +31,6 @@ const mapTestDetails = {
tor: TorDetails
}

// FIXME to have header and stuff
const MeasurementNotFound = () => <h4>Measurement not Found</h4>

const MeasurementContainer = ({ measurement, ...props }) => {
if (measurement === undefined) {
return <MeasurementNotFound />
Expand Down
34 changes: 34 additions & 0 deletions components/measurement/MeasurementNotFound.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* global process */
import React from 'react'
import NavBar from '../NavBar'
import { Container, Flex, Box, Heading, Text } from 'ooni-components'
import { useRouter } from 'next/router'
import styled from 'styled-components'

import OONI404 from '../../static/images/OONI_404.svg'

const WordBreakText = styled(Text)`
word-wrap: break-word;
`

const MeasurementNotFound = () => {
const { asPath } = useRouter()
return (
<React.Fragment>
<NavBar />
<Container>
<Flex flexDirection={['column', 'row']} justifyContent='space-around' alignItems='center' my={5}>
<OONI404 height='200px' />
<Box width={[1, 1/2]} my={[3, 0]}>
<Heading color='blue5' h={4}>Measurement Not Found</Heading>
<WordBreakText color='gray8' as='code'>
{`${process.env.EXPLORER_URL}${asPath}`}
</WordBreakText>
</Box>
</Flex>
</Container>
</React.Fragment>
)
}

export default MeasurementNotFound
17 changes: 11 additions & 6 deletions components/search/FilterSidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,21 @@ class FilterSidebar extends React.Component {
switch(filterName) {
case 'asnFilter':
var asnValue = e.target.value
var asnRegEx = /^(^AS|as)?[0-9]+$/
if (asnValue && asnValue.match(asnRegEx) === null) {
// Accepts only formats like AS1234 or 1234
// https://regex101.com/r/DnkspD/latest
var asnRegEx = /^(AS)?([1-9][0-9]*)$/
if (
typeof asnValue === 'string' &&
(asnValue === '' || asnValue.match(asnRegEx) !== null)
) {
this.setState({
asnError: intl.formatMessage({id: 'Search.Sidebar.ASN.Error'}),
isFilterDirty: false
asnError: false,
isFilterDirty: true
})
} else {
this.setState({
asnError: false,
isFilterDirty: true
asnError: intl.formatMessage({id: 'Search.Sidebar.ASN.Error'}),
isFilterDirty: false
})
}
break
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ooni-explorer",
"version": "2.0.9",
"version": "2.0.10",
"author": "Open Observatory of Network Interference (OONI) <[email protected]>",
"license": "BSD-3-Clause",
"main": "index.js",
Expand Down
5 changes: 5 additions & 0 deletions pages/measurement.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ export default class Measurement extends React.Component {

static async getInitialProps ({ query }) {
let initialProps = {}

if (query.report_id.includes('AS0')) {
return initialProps
}

let client = axios.create({baseURL: process.env.MEASUREMENTS_URL}) // eslint-disable-line
let params = {
report_id: query.report_id
Expand Down
10 changes: 7 additions & 3 deletions pages/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,12 @@ class Search extends React.Component {
}

const measurements = msmtR.data
// drop results with probe_asn === 'AS0'
const results = measurements.results.filter(item => item.probe_asn !== 'AS0')

return {
error: null,
results: measurements.results,
results,
nextURL: measurements.metadata.next_url,
testNamesKeyed,
testNames,
Expand Down Expand Up @@ -240,8 +242,9 @@ class Search extends React.Component {
axios.get(this.state.nextURL)
.then((res) => {
// XXX update the query
const nextPageResults = res.data.results.filter(item => item.probe_asn !== 'AS0')
this.setState({
results: this.state.results.concat(res.data.results),
results: this.state.results.concat(nextPageResults),
nextURL: res.data.metadata.next_url,
show: this.state.show + 50
})
Expand All @@ -268,9 +271,10 @@ class Search extends React.Component {
// XXX do error handling
getMeasurements(query)
.then((res) => {
const results = res.data.results.filter(item => item.probe_asn !== 'AS0')
this.setState({
loading: false,
results: res.data.results,
results,
nextURL: res.data.metadata.next_url
})
})
Expand Down

0 comments on commit 02a32db

Please sign in to comment.