-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
75e26e2
commit ed9268c
Showing
7 changed files
with
87 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package fish.philwants.modules | ||
|
||
import fish.philwants.Credentials | ||
import scala.collection.JavaConversions._ | ||
import org.jsoup.nodes.FormElement | ||
|
||
object LaposteModule extends AbstractModule { | ||
val uri = "https://laposte.net/" | ||
val moduleName = "Laposte" | ||
|
||
def tryLogin(creds: Credentials): Boolean = { | ||
val loginUri = "https://www.laposte.net/accueil" | ||
val resp = get(loginUri) | ||
.validateTLSCertificates(false) | ||
.execute() | ||
|
||
// Parse the form the response | ||
val form: FormElement = resp | ||
.parse() | ||
.select("form") | ||
.first() | ||
.asInstanceOf[FormElement] | ||
|
||
// Update the form data to include username and password | ||
val usernameKey = "login" | ||
val passwordKey = "password" | ||
val formdata: Map[String, String] = form | ||
.formData() | ||
.map { e => e.key() -> e.value() } | ||
.toMap | ||
val updatedFormData = formdata + (usernameKey -> creds.username) + (passwordKey -> creds.password) | ||
|
||
// Send login request | ||
val loginUri2 = "https://compte.laposte.net/login.do" | ||
val loginResp = post(loginUri2) | ||
.header("Content-Type", "application/x-www-form-urlencoded") | ||
.data(updatedFormData) | ||
.cookies(resp.cookies()) | ||
.followRedirects(false) | ||
.validateTLSCertificates(false) | ||
.execute() | ||
|
||
// Check login result | ||
loginResp.statusCode() == 302 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package fish.philwants | ||
|
||
import fish.philwants.modules.LaposteModule | ||
import org.scalatest.{FlatSpec, Matchers} | ||
import TestCredentials._ | ||
|
||
class LaposteModuleTest extends FlatSpec with Matchers { | ||
"Laposte module" should "detect a successful login" in { | ||
val creds = Credentials(LAPOSTE_USERNAME, LAPOSTE_PASSWORD) | ||
val mod = LaposteModule | ||
mod.tryLogin(creds) shouldBe true | ||
} | ||
|
||
it should "detect a failed login" in { | ||
val creds = Credentials(BAD_USERNAME_EMAIL, BAD_PASSWORD) | ||
val mod = LaposteModule | ||
mod.tryLogin(creds) shouldBe false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ object TestCredentials { | |
val GENERIC_USERNAME_EMAIL = ??? | ||
val GENERIC_USERNAME = ??? | ||
val GENERIC_PASSWORD = ??? | ||
val GENERIC_PASSWORD_WITH_CAPITAL = ??? | ||
|
||
val FACEBOOK_USERNAME = GENERIC_USERNAME_EMAIL | ||
val FACEBOOK_PASSWORD = GENERIC_PASSWORD | ||
|
@@ -40,6 +41,9 @@ object TestCredentials { | |
val VIMEO_USERNAME = GENERIC_USERNAME_EMAIL | ||
val VIMEO_PASSWORD = GENERIC_PASSWORD | ||
|
||
val LAPOSTE_USERNAME = "[email protected]" | ||
val LAPOSTE_PASSWORD = GENERIC_PASSWORD_WITH_CAPITAL | ||
|
||
val BAD_USERNAME_EMAIL = "[email protected]" | ||
val BAD_USERNAME = "shardtesting-badusername" | ||
val BAD_PASSWORD = "badpassword" | ||
|