Skip to content

Commit

Permalink
fix(onboard): fail if input is /dev/null
Browse files Browse the repository at this point in the history
When the input is /dev/null, every read returns EOF. In general, it
may also happen that read doesn't work as intended. So, the robust thing
to do here is to ensure that we check the return values. By doing that
we notice of io.EOF errors and we don't proceed with the onboarding.

This diff fixes the issue described by ooni/probe#1281
however it may be that we also want (in the near or not-so-near future)
to stop onboarding if the input terminal is not a tty. This is however a
possible future evolution that should not prevent us for committing and
merging this simple fix that unblocks creating a Debian package.
  • Loading branch information
bassosimone committed Nov 24, 2020
1 parent 7a43975 commit 920c371
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
25 changes: 18 additions & 7 deletions internal/cli/onboard/onboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ func Onboarding(config *config.Config) error {
fmt.Println()
output.Paragraph("OONI Probe checks whether your provider blocks access to sites and services. Run OONI Probe to collect evidence of internet censorship and to measure your network performance.")
fmt.Println()
output.PressEnterToContinue("Press 'Enter' to continue...")
err := output.PressEnterToContinue("Press 'Enter' to continue...")
if err != nil {
return err
}

output.SectionTitle("Heads Up")
fmt.Println()
Expand All @@ -35,7 +38,10 @@ func Onboarding(config *config.Config) error {
fmt.Println()
output.Bullet("Read the documentation to learn more.")
fmt.Println()
output.PressEnterToContinue("Press 'Enter' to continue...")
err = output.PressEnterToContinue("Press 'Enter' to continue...")
if err != nil {
return err
}

output.SectionTitle("Pop Quiz!")
output.Paragraph("")
Expand All @@ -45,7 +51,9 @@ func Onboarding(config *config.Config) error {
Options: []string{"true", "false"},
Default: "true",
}
survey.AskOne(quiz1, &answer, nil)
if err := survey.AskOne(quiz1, &answer, nil); err != nil {
return err
}
if answer != "true" {
output.Paragraph(color.RedString("Actually..."))
output.Paragraph("OONI Probe is not a privacy tool. Therefore, anyone monitoring your internet activity may be able to see which software you are running.")
Expand All @@ -58,7 +66,9 @@ func Onboarding(config *config.Config) error {
Options: []string{"true", "false"},
Default: "true",
}
survey.AskOne(quiz2, &answer, nil)
if err := survey.AskOne(quiz2, &answer, nil); err != nil {
return err
}
if answer != "true" {
output.Paragraph(color.RedString("Actually..."))
output.Paragraph("The network data you will collect will automatically be published to increase transparency of internet censorship (unless you opt-out in the settings).")
Expand All @@ -71,7 +81,9 @@ func Onboarding(config *config.Config) error {
Message: "Do you want to change the default settings?",
Default: false,
}
survey.AskOne(prompt, &changeDefaults, nil)
if err := survey.AskOne(prompt, &changeDefaults, nil); err != nil {
return err
}

settings := struct {
IncludeIP bool
Expand Down Expand Up @@ -113,8 +125,7 @@ func Onboarding(config *config.Config) error {
},
}

err := survey.Ask(qs, &settings)
if err != nil {
if err := survey.Ask(qs, &settings); err != nil {
log.WithError(err).Error("there was an error in parsing your responses")
return err
}
Expand Down
5 changes: 3 additions & 2 deletions internal/output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ func Bullet(text string) {
fmt.Printf("• %s\n", utils.WrapString(text, width))
}

func PressEnterToContinue(text string) {
func PressEnterToContinue(text string) error {
fmt.Print(text)
bufio.NewReader(os.Stdin).ReadBytes('\n')
_, err := bufio.NewReader(os.Stdin).ReadBytes('\n')
return err
}

0 comments on commit 920c371

Please sign in to comment.