mavjs / goPwned

A golang library for HaveIBeenPwned REST API.
MIT License
6 stars 6 forks source link

Multiple consecutive requests will fail #4

Closed Nhoya closed 7 years ago

Nhoya commented 7 years ago

This test case will fail for all the mail except the first,

import (
 "fmt"
 "github.com/mavjs/goPwned"
 "time"
)

func main() {
 fmt.Println("==== HAVEIBEENPWND SEARCH ====")
 mails := []string{"mail1", "mail2", "mail3", "mail4"} #insert valid mail here
 for _, mail := range mails {
  fmt.Println(mail)
  stuff, err := gopwned.GetAllBreachesForAccount(mail, "", "true")
  if err == nil {
   for _, data := range stuff {
    fmt.Println(data)
   }
  } else {
   fmt.Println(stuff)
   fmt.Println(err)
  }
 }
}

the output is

mail1
&{Adobe     0  <nil> false false false false false }
&{MySpace     0  <nil> false false false false false }
mail2
[]
mail3
[]
mail4
[]
invalid character 'R' looking for beginning of value

seems like the requests are too fast and get blocked, i tried with sleep 500 but still nothing, any idea?

mavjs commented 7 years ago

can you provide the full code with the timeout implemented? Also this library currently doesn't do much except make API calls and no checking of rate limiting. The rate limiting doc for it is here: https://haveibeenpwned.com/API/v2#RateLimiting

Nhoya commented 7 years ago

Yea sure, using 2 sec as sleep will work, the problem is that the library should have a better handling for this

import (
 "fmt"
 "github.com/mavjs/goPwned"
 "time"
)

func main() {
 fmt.Println("==== HAVEIBEENPWND SEARCH ====")
 mails := []string{"mail1", "mail2", "mail3", "mail4"} #insert valid mail here
 for _, mail := range mails {
  fmt.Println(mail)
  stuff, err := gopwned.GetAllBreachesForAccount(mail, "", "true")
  if err == nil {
   for _, data := range stuff {
    fmt.Println(data)
   }
  } else {
   fmt.Println(stuff)
   fmt.Println(err)
  }
  time.Sleep(time.Second * 2)
 }
}
mavjs commented 7 years ago

Yes, rate limiting should be there, but it currently doesn't. If you have a way of doing it, send a pull request. I'm working on this on my own time and as a way to learn good practices in go/coding libraries (thus the 2nd committer in the code), so you could say this library isn't feature complete.

For now, I don't really have time or motivation to work on this yet, so closing this for now.

klrkdekira commented 7 years ago

This is a library, rate limit should be done by the users, similarly to any database API.