-
Notifications
You must be signed in to change notification settings - Fork 0
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
dakrone
committed
Mar 20, 2009
0 parents
commit 6078db4
Showing
9 changed files
with
147 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Huzzah! An API for pcapr (http://pcapr.net) | ||
|
||
Doesn't work yet. Do not consume unless you know what you're doing. | ||
|
||
###################################################### | ||
Be sure to change ./features/step_definitions/config.yml to have your | ||
pcapr username and password in order to run the tests | ||
|
||
Cucumber tests: run 'rake features' | ||
###################################################### |
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,6 @@ | ||
$:.unshift(File.dirname(__FILE__) + '/../../../lib') | ||
require 'cucumber/rake/task' | ||
|
||
Cucumber::Rake::Task.new do |t| | ||
t.cucumber_opts = "--language en" | ||
end |
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,16 @@ | ||
Feature: Downloads | ||
In order to retrieve data from pcapr | ||
As a regular user | ||
I want to be able to download a pcap file | ||
|
||
Scenario Outline: Download a pcap file | ||
Given I have a pcap file id <p_id> | ||
When I download the pcap file | ||
Then the pcap file should be download | ||
|
||
Examples: | ||
| p_id | | ||
| 100 | | ||
| 101 | | ||
|
||
# vim: set ts=2 sw=2 |
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,3 @@ | ||
--- | ||
:username: your-username-here | ||
:password: your-password-here |
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,24 @@ | ||
$:.unshift File.join(File.dirname(__FILE__)) | ||
|
||
require 'spec/expectations' | ||
require 'rcapr' | ||
require 'env' | ||
|
||
Before do | ||
@rc = Rcapr.new(@username, @password) | ||
end | ||
|
||
After do | ||
end | ||
|
||
Given /^I have a pcap file id (\d+)$/ do |id| | ||
pending | ||
end | ||
|
||
When /^I download the pcap file$/ do | ||
pending | ||
end | ||
|
||
Then /^the pcap file should be download$/ do | ||
pending | ||
end |
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,6 @@ | ||
require 'yaml' | ||
|
||
f = File.new(File.dirname(__FILE__) + "/config.yml", "r") | ||
@config = YAML.load(f) | ||
@username = @config[:username] | ||
@password = @config[:password] |
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,24 @@ | ||
$:.unshift File.join(File.dirname(__FILE__)) | ||
|
||
require 'spec/expectations' | ||
require 'rcapr' | ||
require 'env' | ||
|
||
Before do | ||
@rc = Rcapr.new(@username, @password) | ||
end | ||
|
||
After do | ||
end | ||
|
||
Given /^I have a pcap file ([\S.]+)$/ do |pcap_file| | ||
@filename = pcap_file | ||
end | ||
|
||
When /^I upload the pcap file$/ do | ||
@result = @rc.upload(@filename) | ||
end | ||
|
||
Then /^the pcap file should be uploaded$/ do | ||
@result.should =~ /\{ okay: true, id: "([\S]+)" \}/ | ||
end |
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,15 @@ | ||
Feature: Uploads | ||
In order to contribute data to pcapr | ||
As a regular user | ||
I want to be able to upload a pcap file | ||
|
||
Scenario Outline: Upload a pcap file | ||
Given I have a pcap file <filename> | ||
When I upload the pcap file | ||
Then the pcap file should be uploaded | ||
|
||
Examples: | ||
| filename | | ||
| t.pcap | | ||
|
||
# vim: set ts=2 sw=2 |
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,43 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'rubygems' | ||
require 'httparty' | ||
require 'pp' | ||
require 'json' | ||
|
||
class Rcapr | ||
def initialize(username, password) | ||
@username = username | ||
@password = password | ||
@api = RcaprAPI.new(@username, @password) | ||
end | ||
|
||
def upload(filename) | ||
result = @api.upload(filename) | ||
#pp result | ||
# TODO: de-stub | ||
#return '{ okay: true, id: "uploaded-pcap" }' | ||
end | ||
end | ||
|
||
# (598)-~% curl --basic -u user@domain.com:******* -F file=@t.pcap -F description="testing the API" -F tags="api" http://www.pcapr.net/api/upload | ||
# ({id:"c6be820e5c1cf9f9f37871602c7a8ed1", okay:true}) | ||
|
||
class RcaprAPI | ||
include HTTParty | ||
base_uri 'http://www.pcapr.net/api' | ||
|
||
def initialize(u, p) | ||
@auth = {:username => u, :password => p} | ||
end | ||
|
||
def upload(file) | ||
begin | ||
options = { :basic_auth => @auth, :file => file } | ||
self.class.post('/upload', options) | ||
rescue | ||
return {:okay => false}.to_json | ||
end | ||
end | ||
|
||
end |